I am trying to create a SCCM package for installing/uninstalling VS Code on Windows. I am able to install without any problems, but I cannot get it to uninstall.
Here is what I have tried:
For reference, VSCodeSetup-x64-1.28.0.exe is the executable I used for installing vs code.
From Powershell:
Start-Process -FilePath .\VSCodeSetup-x64-1.28.0.exe -ArgumentList "/uninstall" -Wait -PassThru (This just executes the installer with no options to uninstall)
Start-Process -FilePath "C:\Program Files\Microso
ft VS Code\Code.exe" -ArgumentList "/uninstall" -Wait -PassThru (This just opens VS Code)
I looked at the following site for command line options, but no mention of uninstall.
http://jrsoftware.org/ishelp/index.php?topic=setupcmdline
Looking at the uninstall string in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ (For me it was {F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1 but this could be version dependent) it seems like there is a REG_SZ QuietUninstallString which in my case pointed to:
"C:\Program Files\Microsoft VS Code\unins000.exe" /SILENT
So you could either if those are all default instalations just hard code that path (relative to where you installed it so possibly program files (x86) or some other path) or read the string before uninstall in some script and use it directly (might also be affected by WoW64 I only did a quick test on a 32bit system)
Related
I am trying to create an intunewin file to update dell command update on all computers (via MS endpoint manager).
Dell CU will not install itself, if the older version of the app is present on the pc. Or rather it will install, but it won't run.
Solution - To create a powershell script, that first uninstalls the older versions of dell CU, and only then installs the newest one.
The code:
Remove-Item -Path "C:\Program Files\Dell\CommandUpdate" -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -Path "C:\Program Files (x86)\Dell\CommandUpdate" -Recurse -Force -EA SilentlyContinue -Verbose
./Dell-Command-Update-Windows-Universal-Application_601KT_WIN_4.5.0_A00_01.EXE
This works just fine, when run like this on my computer. Actually I run the cmd script:
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File .\script.ps1
Where script.ps1 is the first script above.
So I have 3 files in the folder - the ps1 script, the cmd command, and the EXE file itself. From these 3 I create the intunewin file.
When pushed via intune, the app does not install itself. I can see 'downloading' notification, but never receive installation notification, neither successful nor failed one.
Can this be related to intune settings itself? The detection method and install command are most likely correct and were working before, when I was just using the exe file for intunewin creation.
I have to change this, because Dell CU won't install itself if the older version is there - as mentioned in the first sentence.
I assume this might be related to the powershell code. Maybe intune does not understand
./Dell-Command-Update-Windows-Universal-Application_601KT_WIN_4.5.0_A00_01.EXE
anymore, when it is given intunewin file instead?
If that's the case, how can I modify my script to 'make sense in intune'?
Thank you in advance for all the advices
I've written a script that downloads the MS ODBC driver, installs it, then checks the new driver .dll exists. However, I'm stuck on the "installs it" part.
The best version of the install command I have right now is: Start-Process -Filepath "msiexec.exe" -ArgumentList "/i msodbcsql.msi", "/qb", "IACCEPTMSODBCSQLLICENSETERMS=YES"
When I run this on its own (to troubleshoot it), however, the installer launches and immediately displays the error:
The required IACCEPTMSODBCSQLLICENSETERMS=YES command-line parameter is missing.
If I run Start-Process -Filepath msiexec -ArgumentList /i, "msodbcsql.msi" the regular GUI installer starts up which presumably means the "/qb", "IACCEPTMSODBCSQLLICENSETERMS=YES" part of the command is the problem.
I'm having no luck with this in spite of adapting every example I can find on the web. I'd be grateful for help!
The problem: I wasn't running PowerShell in Administrator mode 😖
Having some weirdness where Powershell is not executing this command correctly. It can't understand the INSTALLFOLDER or TARGETDIR and just throws up the Windows Installer help box.
Whereas command prompt processes this just fine??? It's very weird. PS version is 5.1.18362 I believe.
the command is
msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn
My msi is a Wix installer msi and has the property INSTALLFOLDER
This is not how you run this command in PowerShell. There are several ways to run external command in PowerShell and it a well-documented use case. Links to follow
• Using PowerShell and external commands and their parameters or
switches.
Running external commands, always require special consideration.
• PowerShell: Running Executables
• Solve Problems with External Command Lines in PowerShell
• Top 5 tips for running external commands in Powershell
• Using Windows PowerShell to run old command-line tools (and their
weirdest parameters)
• Execution of external commands in PowerShell done right
https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right
https://mnaoumov.wordpress.com/2015/03/31/execution-of-external-commands-native-applications-in-powershell-done-right-part-2
https://mnaoumov.wordpress.com/2015/04/05/execution-of-external-commands-native-applications-in-powershell-done-right-part-3
http://edgylogic.com/blog/powershell-and-external-commands-done-right
• Quoating specifics
https://trevorsullivan.net/2016/07/20/powershell-quoting
PowerShell has a list of characters that mean specific things, vs what cmd.exe implementation means, and if you need those, they must be properly terminated. See the below
About Special Characters
PowerShell - Special Characters And Tokens
So, to make your command work in the PowerShell consolehost, ISE, VSCode, do something like this...
# Using teh Call operator
& 'msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn'
or
... this...
# Using Start-Process
$ConsoelCommand = 'msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn'
Start-Process powershell -ArgumentList "-NoExit","-Command &{ $ConsoleCommand }" -Wait
Make sure you check for existence of that actual folder, but it's likely the problem is the space
instead of this:
msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn
try this:
invoke-command -scriptblock {cmd /c "msiexec.exe /i `"C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi`" INSTALLFOLDER=`"C:\Installation` Test`" /qn"}
Notice that all the double-quotes are escaped AND a the space in "C:\Installation Test" is escaped. Your problem will boil down to this space and how you handle it. Also try changing double to single quotes. If you decide to use variables in your command, definitely add the strings (""+"") to create the command so that it will expand the variables correctly.
I have a Powershell script to install TCP/IP printers on Windows 10 that uses PNPUTIL to load drivers. When the script is run from a Powershell window, everything works great.
When I launch the script from a shortcut using the format
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1
I get an error 'The term 'pnputil.exe' is not recognized as the name of a cmdlet, function, script file, or operable program' when PNPUTIL is called. The rest of the script runs fine.
Relevant code:
Write-Host `n 'Installing printer driver..'
pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"
Any ideas as to why this won't work when launched from a shortcut?
EDIT:I tried using
& pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"
as referenced in
Running CMD command in PowerShell
but I still get the error. I also tried
start-process pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"
but got a similar error that pnputil.exe could not be found.
Both of these options work from a Powershell prompt, but again, fail when launched from a shortcut.
Thank you in advance.
You're invoking a 32-bit instance of PowerShell on a 64-bit system, and that instance doesn't see pnputil.exe (by filename only).
Instead of:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1
use:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1
Folder C:\Windows\SysWOW64 is where the 32-bit executables live.
Paradoxically, for historical reasons, it is C:\Windows\System32 that houses the 64-bit executables.
If, for some reason, you do need to run a 32-bit instance of PowerShell, you can invoke pnputil.exe by its full path:
It only exists as a 64-bit executable in the 64-bit system folder, which 32-bit processes can access as C:\Windows\SysNative:
C:\Windows\SysNative\pnputil.exe
Am trying to extract Ruby Devkit Tdm package using below command,
Start-Process "C:\DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe" -ArgumentList "-o'C:\Ruby-DevKit' -y" -PassThru -Wait
but its having 7-zip unknown error. I found in Google for NSIS script which has to perform this and below is the query,
ExecWait '"$TEMP\${devkit_installer}" x -o"${devkit_path}" -y /silent /noreboot /nocancel /noicons' $1
Is there any similar way to perform silent unzip this using powershell?
The problem is the single quotes around the folder path in your ArgumentList, Start-Process isn't passing them as you would expect. You only need them if you have a space in your path so you can just remove them in this case:
Start-Process C:\DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe -ArgumentList "-oC:\Ruby-DevKit -y" -PassThru -Wait
If you just used the call operator to run the command it works fine with single quotes, but the installer itself does not wait to finish so the script continues whilst the install is still in process.
& C:\DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe -o'C:\Ruby-DevKit' -y
So there's two ways around your issue depending on if you want the script to wait for the install or not.