Enqueuing MSI installs - via Powershell - powershell

I'm trying to install both the 32-bit and the 64-bit versions of Visual Studio 2005 as part of a Powershell script on our Win2008 instances. When I try to invoke the installation of both EXE files without a break, the second EXE (x86) doesn't execute since the x64 one hasn't finished installing.
So, I added a 5 sec sleep after each invoke and that seems to work now. However, I'm not very happy with this solution as it looks more like a workaround than a proper way to handle the task at hand.
Is there a better way to do this - maybe enqueue the files for install - so they execute one after another?
Here are the specific lines of code:
if ($OSArchitecture -eq "64-bit")
{ Write-Output "Found 64-bit OS. Installing both VC++ files for compat"
start-process .\vcredist_x64.exe /Q
start-sleep 5
start-process .\vcredist_x86.exe /Q
start-sleep 5
}

You must use the Start-Process -Wait parameter.
-Wait Waits for the specified process to complete before accepting more input. This parameter suppresses the command
prompt or retains the window until the process completes.

Related

How to install MS ODBC driver using PowerShell

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 😖

Run executable in powershell without waiting for return

This is really basic, but I can't find the answer. The installer sets up my path so that I can just type the command:
ng serve
at the command prompt and the script runs. I don't want to wait for this program to finish (it's a server, after all). How do I launch the same script (it's a CMD script as far as I can tell) from Powershell without waiting for it to finish (and without having to find the source directory for the script)?
If it's acceptable to terminate the server when the PowerShell session exits, use a background job:
In PowerShell (Core) 7+
ng server &
In Windows PowerShell, explicit use of Start-Job is required:
Start-Job { ng server }
Both commands return a job-information object, which you can either save in a variable ($jb = ...) or discard ($null = ...)
If the server process produces output you'd like to monitor, you can use the Receive-Job cmdlet.
See the conceptual about_Jobs topic for more information.
If the server must continue to run even after the launching PowerShell session exits, use the Start-Process cmdlet, which on Windows launches an independent process in a new console window (by default); use the -WindowStyle parameter to control the visibility / state of that window:
Start-Process ng server # short for: Start-Process -FilePath ng -ArgumentList server
Note: On Unix-like platforms, where Start-Process doesn't support creating independent new terminal windows, you must additionally use nohup - see this answer.

Determine when a verysilent install is complete [duplicate]

This question already has answers here:
How to tell PowerShell to wait for each command to end before starting the next?
(10 answers)
Closed 7 years ago.
When I run an installation from Inno Setup with:
Installer.exe /VERYSILENT
The command immediately returns even though the install takes about 10 minutes. So, if I run:
Installer.exe /VERYSILENT
DoNextThing.exe
DoNextThing.exe runs while the installer.exe is still installing.
I would like to run some configuration after the install is successful. Right now, in powershell, I do the following:
$h = Start-job -name Installer -ScriptBlock {."Installer.exe" /VERYSILENT}
$h # the ps job control commands show this job as complete very quickly
sleep 10
$x = Get-Process -ProcessName Installer
while ($x -and ! $x.HasExited)
{
write-output "waiting ..."
sleep 10
}
# Do some configuration
Although this seems to work, I think I must be missing a better way to do this. I do not want to make it part of the installer as this configuration is just for the Jenkins test environment.
Any ideas why the powershell job management does not work for this? Am I using powershell incorrectly, or is the Installer.exe generated by Inno Setup not working well with powershell? [should I be using cmd.exe instead of powershell?]
You might have to just add a command to the RUN section in inno-setup to create a file "IamFinishedInstalling.txt" as the last thing it does.
Your powershell can then block on that file rather than try to figure out process or job statuses.
while (! (Test-Path "IamFinishedInstalling.txt")) { sleep 10 }
If the installer.exe is really returning before the install is finished, this may be the simplest thing you can try.
Why use a job at all? Just run the installer using the installer command. When the executable completes, PowerShell will continue on to the next line of the script.

Monitor ccmsetup.exe installation status usng powershell

This question is realted to SCCM Client installer ccmsetup.exe. When we run manually ccmsetup.exe; it starts the installation process and exit from command prompt. I cannot monitor the installation process from commandline. It starts recording installation status in ccmsetup.log file. However time to execute completely varies per system.
How can I monitor ccmsetup.exe installation status using powershell.
I am using command as below:
Invoke-Command { C:\Client\ccmsetup.exe /Source:"C:\Client" SMSSITECODE=PPR FSP=Server1.ADDOMAIN.COM}
Thanks & regards,
Kedar
Give a shot to the start-process cmdlet :
start-process C:\Client\ccmsetup.exe -ArgumentList #( '/Source:"C:\Client"' , "SMSSITECODE=PPR" , "FSP=Server1.ADDOMAIN.COM" -wait
And tell me it works, because it works for me :)
NB : the use a simple quotes allows double-quotes to be passed to the process launched.

How can I make PowerShell wait until a command is complete before proceeding?

I'm using the following line to uninstall office 2007 based on its Product ID
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/uninstall {90120000-0030-0000-0000-0000000FF1CE}"
I'd like to force a reboot after the uninstall is complete however using -Wait or piping the results to Out-Null don't wait until the uninstall is complete before processing the next line which is a restart. I've also tried using cmd to uninstall but with the same result.
cmd /c "msiexec.exe /uninstall {90120000-0030-0000-0000-0000000FF1CE}"
Is there any way to force powershell to wait until the uninstall is complete before processing the Restart-Computer command? I was thinking possibly writing something that detects when the setup.exe process stops before proceeding to the restart?
Start-Process has a wait parameter:
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/uninstall {90120000-0030-0000-0000-0000000FF1CE}" -wait
The solution to restart after an misexec.exe uninstallation is to add the /forcerestart parameter to the msiexec call instead of trying to restart in powershell (Credits to Matt):
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList #("/uninstall {90120000-0030-0000-0000-0000000FF1CE}", "/forcerestart")
The simplest workaround: pipe the result. This will force a wait until the process is finished.
No need for start-process or cmd.
You could pipe to out-default, out-file, out-null or out-host, depending on how you want to handle the output. (If you don't care about the output, simply use out-null.)
& msiexec.exe /uninstall "{90120000-0030-0000-0000-0000000FF1CE}" | Out-Null
My suggestion for this is to actually get the Office Removal Tool from Microsoft and extract the VBS script from it. Run that in a Start-Process with the -wait argument, and reboot afterwards. It will not only attempt to gracefully remove Office with msiexec as you are doing, it will also go back and clean up any straggling files or registry entries in case the application is corrupt and will not uninstall nicely.