SCCM | Powershell Detect in User Context

When deploying applications to users there always comes a time when you need to detect an application is installed whilst in the user context. It becomes abit of an issue when checking files and folders exist in the users profile as by default SCCM runs with administrative privileged and not as the user. I’m sure there are a few way around this but the script i created below i found the most useful as it still work in Powershell version 2 which we had on our Windows 7 machines.

  1. Configure your application as to how you would like it to install
  2. Run the application whilst already logged in as a standard user (this is will ensure the application can run and isn’t stopped by any policy)
  3. Locate where the application is copying files too or creating files too
  4. Amend the below script with the location of the newly created files so SCCM can discover if the application is installed
    [String] ${stUserDomain},[String] ${stUserAccount} = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name.split("\")
    $Path = "C:\PrintingInfo\${stUserAccount}.txt"
    If(Test-Path $Path) { "Installed" } Else { "" }
  5. The first line will get the logged in username and remove the <domain>\
    For example: Contoso\Joe.Bloggs will be shortened to Joe.Bloggs
  6. Set the path
    For example: C:\Users\${stUserAccount}\Desktop\File.txt
  7. Set the detection method as a Powershell Script and copy and paste the code
  8. Deploy and test!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.