Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Problems running a Powershell script on a task sequence

Status
Not open for further replies.

Juan M.

Member
Messages
20
Reaction score
1
Points
3
Hi,
I've been having problems with an install for a looong time.
I need to install the latest Salesforce plugin for outlook on my companies computer but many different versions are installed which I need to uninstall prior to installing the newer version.
To do so, I have found a Powershell script that if I run from PS ISE works correctly however, if I do it from a task sequence it says it has run but it doesn't do anything.
This is how I did it:
  1. Created a package with the .ps1 file with no program.
  2. Added a Run powershell script step where I invoke the package and specified the script name.
After many troubleshooting I think it could have to do with the account the task sequence is executed.

The PS script is the following:
Code:
            $uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Salesforce*" } | select UninstallString
            $uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Salesforce*" } | select UninstallString
            
            if ($uninstall64) {
            $uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
            $uninstall64 = $uninstall64.Trim()
            Write "Uninstalling..."
            start-process "msiexec.exe" -arg "/X $uninstall64 /q" -Wait}
            if ($uninstall32) {
            $uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
            $uninstall32 = $uninstall32.Trim()
            Write "Uninstalling..."
start-process "msiexec.exe" -arg "/X $uninstall32 /q" -Wait}

it should find the uninstall string for the app and execute it.
Also, the app I'm trying to find is installed on the user profile, and if the uninstall string is run from another account it wont find it.... this is why I think it might have to do with the account
 
Have you tried running the PS script manually and tested if it works fine (This is just to check if the PS script is works) ?. The script that you have deployed runs with a system account and you want to run it with locally logged in user account. I would suggest you try some other method than powershell ?.
 
Yes, I have tried running the PS script directly on the machine and it works correctly.
I will try another method, it was just that PS was with what I felt more confident.
Thank you
 
Finally got it to work as a package with a program. Had forgot that a program inside a package can be run as logged in user....
Don't know why I didn't think about this before..

Thanks for taking a look anyway.
 
Status
Not open for further replies.
Back
Top