Powershell - Start Process MSI Not Installing - Was working before - powershell

I have that line of code who was working before, but not anymore:
Start-Process msiexec.exe -ArgumentList '/qn /i "C:\temp\connecteur\Druide\Antidote-Connectix11.msi"' -Wait -Verbose | Out-null
I try to catch error, but it's just do... nothing. I have a short waiting time, and end the script with a Completed status. Any idea what can be the error here ?
Thanks

Related

How to add like a loop or if else statement to do the task 1 by 1

I want to add a task sequence, meaning the script will wait the first task to be finished first, then proceed with next task. If task receives error, it will not proceed and probably will create log for that.
WindowsSensor_F7C855810C3B47FC8931D2E5E9E889BF-57.exe /install /quiet /norestart
"%ProgramFiles%\CrowdStrike\CSInstallGuard.exe" PW="nzhHLfrpy5rqTFVsne8D"
if exist "%ProgramFiles%\Cylance\Desktop\CylanceSvc.exe" msiexec /x {2E64FC5C-9286-4A31-916B-0D8AE4B22954} /qn /norestart
Below is the code I come out. Can someone clean it up
Start-Process "WindowsSensor_F7C855810C3B47FC8931D2E5E9E889BF-57.exe" /install /quiet /norestart | Out-null
Start-Process "%ProgramFiles%\CrowdStrike\CSInstallGuard.exe" PW="nzhHLfrpy5rqTFVsne8D" | Out-null
if (test-path %ProgramFiles%\Cylance\Desktop\CylanceSvc.exe .PathType leaf){
msiexec /x {2E64FC5C-9286-4A31-916B-0D8AE4B22954} /qn /norestart | Out-null
}
else {
break
}
You can pipe output like
WindowsSensor_F7C855810C3B47FC8931D2E5E9E889BF-57.exe /install /quiet /norestart | Out-null
This will make powershell to wait for the command to finish.
... actually I just retyped your question in the search bur and found similar ones with great answers, for example look at
this question.

ExitCode 1603 when silently installing a .msi

I'm trying to write a script that installs a .msi silently. When I run the command from the Powershell command line as a ./thing.msi with the argument /qn, it works just fine.
However, now that it is in a script it is returning a 1603 error ("A fatal error occurred during install"). If I try to switch it up and go to /qb with or without /quite, it runs, but it's not silent. Using -WindowStyle Hidden is doing nothing of note either. Any thoughts?
$InsightInstall = Start-Process -FilePath $PSScriptRoot\support.msi -
ArgumentList "/quiet /qb" -Wait -Passthru -WindowStyle Hidden
if($InsightInstall.ExitCode -eq 0)
{
Write-Host "Installation complete."
}
else
{
Write-Host "Failed with ExitCode" $InsightInstall.ExitCode
pause
}
You don't need to try that hard (I don't think Start-Process is needed). Just run msiexec and specify the package, followed by parameters.
msiexec /i d:\path\package.msi /quiet

Installing AppFabric 1.1 with PowerShell DSC results in modal dialog error

I'm trying to automate the installation of AppFabric 1.1 on a Windows 2012 R2 server using PowerShell DSC. This is actually part of me trying to automate the SharePoint Foundation install and configuration, but AppFabric 1.1 is a pre-requisite. Below is a snippit from my DSC config script:
Script InstallSharePointPreRequisites
{
GetScript = { Return "InstallSharePointPreRequisites" }
TestScript = {$false}
SetScript = {
Start-Process -FilePath 'c:\temp\SharePoint\pre\MicrosoftIdentityExtensions-64.msi' -ArgumentList '/qn' -Wait | Write-verbose
Start-Process -FilePath 'c:\temp\SharePoint\pre\setup_msipc_x64.msi' -ArgumentList '/qn' -Wait | Write-verbose
Start-Process -FilePath 'c:\temp\SharePoint\pre\sqlncli.msi' -ArgumentList '/qn' -Wait | Write-verbose
Start-Process -FilePath 'c:\temp\SharePoint\pre\Synchronization.msi' -ArgumentList '/qn' -Wait | Write-verbose
Start-Process -FilePath 'c:\temp\SharePoint\pre\WcfDataServices.exe' -ArgumentList '/quiet' -Wait | Write-verbose
Start-Process -FilePath 'c:\temp\SharePoint\pre\appfabric\setup.exe' -ArgumentList '/i cacheclient","cachingService","CacheAdmin /gac /l c:\temp\appfabric.log' -Wait | Write-verbose
Start-Process -FilePath 'c:\temp\SharePoint\pre\AppFabric1.1-RTM-KB2671763-x64-ENU.exe' -ArgumentList '/quiet' -Wait | Write-verbose
}
DependsOn = "[File]GetSharePointFiles"
}
I know....the "TestScript = $false" is bad form, but I'm just trying to get the install to run at this point. :)
Anyway, when the DSC run get to the appfabric\setup.exe it's throwing the following exception:
"{"Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."}"
When I run the Start-Process line from a normal PS prompt it installs fine and doesn't show a visible modal dialog box. I've also tried using the AppFabric setup EXE with similar switches with the same result. I'm sort of at a loss here. Has anyone else been able to install AppFabric 1.1 using PowerShell DSC? Or SharePoint Foundation 2013 for that matter? If so, how? I haven't been able to find good documentation on this scenario yet.
Thanks,
A
I solved this problem. First, there was a typo in my script. The app fabric setup line had CachAdmin rather than CacheAdmin (was missing the 'e' in cache). It took me some time and writing it a few more times to figure that out. After setting that, it is installing fine. Darn, old eyes and fat fingers... Thanks for looking. :)
A

Find exit code for executing a cmd command through PowerShell

I am using a silent installation command to install software. I am running this command from PowerShell 3.0.
$silentInstall = C:\Users\Admin\Documents\Setup-2.0.exe exe /s /v"EULAACCEPTED=\"Yes\" /l*v c:\install.log /qn"
Invoke-Expression $silentInstall
This runs the command which installs the software, but it does not wait for it to complete and goes ahead with the next lines of code. I want to have control over the installation so that I would know if it's completed or not.
How do I get an error code for the Invoke-Expression cmdlet so that I can get to know if the cmd executed successfully or not?
It depends on how the EXE file runs - sometimes it will kick off a separate process and return immediately, and in such cases this usually works -
$p = Start-Process -FilePath <path> -ArgumentList <args> -Wait -NoNewWindow -PassThru
$p.ExitCode
Otherwise this usually works -
& <path> <args>
$LASTEXITCODE
Or sometimes this -
& cmd.exe /c <path> <args>
$LASTEXITCODE
It looks like you're running an MSI installer. When running from the console, control is immediately returned while MSI forks a new process to run the installer. There is no way to change this behavior.
What you'll probably need to do is use Get-Process to find a process named msiexec, and wait for it to finish. There is always an msiexec process running, which handles starting new installers, so you'll need to find the msiexec process that started after your install began.
$msiexecd = Get-Process -Name 'msiexec'
C:\Users\Admin\Documents\Setup-2.0.exe exe `
/s `
/v"EULAACCEPTED=\"Yes\" /l*v c:\install.log /qn"
$myMsi = Get-Process -Name 'msiexec' |
Where-Object { $_.Id -ne $msiexecd.Id }
$myMsi.WaitForExit()
Write-Verbose $myMsi.ExitCode
You shouldn't need to use Invoke-Expression:
& C:\Users\Admin\Documents\Setup-2.0.exe /s /vEULAACCEPTED=Yes /l*v C:\install.log /qn

PowerShell: Start-Process with wait option taking long time to return

I have the following script:
$mArgs = #('myProj.vcxproj', '/t:Clean,Build' ,('/p:configuration=DEBUG'+';platform=win32;OutDir=./'))
Start-Process msbuild.exe -ArgumentList $mArgs -RedirectStandardOutput $tempFile -wait
The above successfully builds myProj. However, it takes a really long time to return. When the above line is reached, I see the msbuild windows for about 2 minutes. Then, it closes. After that, it takes another 8 minutes for the process to complete. If I just run the above in a cmd window, it takes about 2 minutes for it to complete.
I tried starting the process cmd.exe and passing msbuild as a parameter, but got the same result.
I also tried Invoke-Expression and also got the same results.
Does anyone have a clue what can be causing this delay ?
Thanks in advance!
I am using PowerShell v4.0 Start-Process for running MSBuild on Win2012R2. Usually build time of my solution is 1 min, but on build server it is 16 min. It takes MSBuild 15 min to close all nodes and finally exit (16 min to print "Finished!!!").
PowerShell code:
$process = Start-Process -FilePath $fileName -ArgumentList $arguments
-WorkingDirectory $workingDir -NoNewWindow -PassThru -Wait
Write-Host "Finished!!!"
$exitCode = $process.ExitCode
MSBuild args:
$commandLine = "/nologo /p:Configuration=Release;Platform=x64 /maxcpucount:2"
+ " "+ $dir + "MySolution.sln"
After adding /nodeReuse:false to MSBuild command line the build time is back to normal (1min).
Here is the working code:
function PsStartProcess([string]$fileName, [array]$arguments, [string]$workingDir)
{
if (!$workingDir)
{
$workingDir = [System.IO.Directory]::GetCurrentDirectory()
}
$process = Start-Process -FilePath $fileName -ArgumentList $arguments -WorkingDirectory $workingDir -NoNewWindow -PassThru -Wait
Write-Host "Finished!!!"
$exitCode = $process.ExitCode
$process.Close()
return $exitCode
}
$exeFileName = "c:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
$commandLine = "/nologo /p:Configuration=Release;Platform=x64 /maxcpucount:2 /nodeReuse:false" + " "+ $dir + "MySolution.sln"
PsStartProcess $exeFileName $commandLine $binDir
I had same issue using devenv.exe to compile like this
Start-Process $devenv $args -Wait
That would take forever. I reformatted the code to this
$proc = Start-Process $devenv $args -PassThru
$proc.WaitForExit()
And it is flying. In my case it is compilation of multiple solutions (40+) in the loop, and in perf-mon I don't see many active MSBuild/Devenv processes. There are few of each but all "terminated". And memory is OK. So, good option.
Why are you using Start-Process to run MSBUILD? I run it directly within PowerShell e.g.:
C:\PS> msbuild myproj.vcxproj /t:clean`,build /p:configuration=DEBUG`;platform=win32`;OutDir=. > $tempfile
Just be sure to escape the characters that PowerShell would normally interpret like , and ;.
I ran into this problem today. What I found is that msbuild waits for VBCSCompiler.exe (located in the visual studio installation folder) to close. There is a config to this exe with a keepalive setting which defaults to 600 seconds. Setting this to 1 second will bypass this problem.
Just observed the script and found that the first Line of the script seems to have a missing Single Quote. Please try again with the missing quote and report if that helps?
On Windows 7 the process returns immediately after completion of the build, but on Windows 8 I have the same problem. If possible, I'll try to test with some other environments as well.