Task Sequence can't find file in users AppData folder

net1994 121 Reputation points

Hi all - I'm trying to uninstall a program (let’s call it XYZ) that is EXE based, not MSI. It wasn't originally installed by SCCM and installed by end users into their own user profiles. The uninstaller (Uninstall.exe) is located in the user’s profile: 'C:\Users\%randomuser%\AppData\Roaming\XYZ Program.' There is one task sequence step as a ‘Run Command.’ However, as it's a Task Sequence, it runs in system context. When I specify %APPDATA%\XYZ Program in the 'Start in' folder, it actually points to C:\Windows\system32\config\systemprofile because the task sequence runs in the system context. Of course, it fails as it can't find Uninstall.exe which is in the user’s profile.

What we need is to have the run command find the uninstall.exe where it is found in any users appdata roaming folder. Questions:

  1. Perhaps I can adjust my environmental variables for the 'Start in' section? I've scoured the net and can't find anything like this. Don't think it's possible.
  2. If the Task Sequence can't search other users appdata\roaming folders, is there a PowerShell command I can use and add it as a step in the task sequence to run this one liner against users’ profile? Scour each users roaming folder and then run the command if there is a match.


Microsoft Configuration Manager Application
Microsoft Configuration Manager Application
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Application: A computer program designed to carry out a specific task other than one relating to the operation of the computer itself, typically to be used by end users.
376 questions
Microsoft Configuration Manager
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rahul Jindal [MVP] 7,431 Reputation points MVP

    Why not use a package, script, application to uninstall the app from user’s profile space? There are limitations when it comes to executing a TS to address user context based scenarios.

  2. AlexZhu-MSFT 3,706 Reputation points Microsoft Vendor


    If we want to uninstall a per-user application, it seems we can use powershell to locate the uninstaller first, add the silent switch and run the uninstallation command. Here's the sample script to illustrate how it works and you may modify it and test in your environment.

    $a = Get-ChildItem -Path c:\users\ -Recurse -force -ErrorAction SilentlyContinue | ? {$_.name -like '*uninst.exe*' -and $_.directoryname -like '*youdao*'}  
    $command = $a.directoryname + "\" + $a.name  
    invoke-command $command  

    test with SYSTEM account in the client computer


    add a run Powershell step to the task sequence (since the script is simple, we can enter it directly without creating a package)


    If the response is helpful, please click "Accept Answer" and upvote it.

  3. net1994 121 Reputation points

    Hi Alex,

    Thanks so much. Here is additional info. I already know the path and uninstall exe that needs to be used: %APPDATA%\Juniper Networks\Setup Client\uninstall.exe /silent-1


    1. As I know the path where the uninstaller is, can I put that directly into the PS script?
    2. If I copy the PS script directly into the task sequence step (not as a powershell ps1 file), will it be able to run as we are trying to perform an action within the users profile, however Task Sequences run in system context?