I am trying to make autoinstall my application by powershell.
I am trying like this
$command = "cmd.exe /c C:\myApp_Installer.exe /s /v /qn"
$process = [WMICLASS]"\ROOT\CIMV2:win32_process"
$process.Create($command)
Installer starts but I still must click Install button.
Related
I'm trying to install an application that is an MSI file during the build process of an image with Dockerfile.
I can get the MSI to install properly when I enter a PowerShell session on the container by running:
C:\Windows\Syswow64\msiexec.exe /i "C:\Folder\File Name with spaces.msi" /qn /l*v "C:\log.log"
I have tried everything I can think with various RUN commands using powershell and cmd in the dockerfile.
Anyone have any ideas if this is just a matter of properly escaping quotes or the spaces?
Thanks,
Using powershell you can install msi file using below piece of code.
$msiPath = "your msi file path"
$arguments = "/i `"$msiPath`" /quiet"
Start-Process msiexec.exe -ArgumentList $arguments -Wait
Use same quotes
I'm a complete newbie when it comes to scripting Powershell but have a reasonable experience with writing Bat files.
I have a powershell script that unzips a bat, a reg file and a msi, the powershell script then launches the bat file, I dont think this is the best way to do it, is there a way to just get the powershell script to unzip and then install the msi and reg files rather than running a seperate bat file?
Here are the 2 files:
BAT:
#echo off
echo Installing Teamviewer, please wait...
msiexec /qn /i "C:\Temp\TeamViewer.msi" /passive
echo[
regedit /s C:\Temp\TeamViewer_Settings.reg
Pause
exit
PS:
$BackUpPath = "C:\Temp\Install.zip"
$Destination = "C:\Temp"
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::ExtractToDirectory($BackUpPath, $destination)
Start-Process "C:\Temp\installer.bat"
Is there a way to just run the powershell script and extract and install the required files?
Many thanks and be kind, this is my first Powershell script.
you use start-process to run the bat file so just use the same to run the msi file instead.
Since there isnt a powershell cmdlet to import regitry files you can use regedit.exe to import the reg file.
Start-Process -FilePath 'msiexec.exe' -ArgumentList "/qn /i 'C:\Temp\TeamViewer.msi' /passive" -Wait
Start-Process -Filepath 'regedit.exe' -ArgumentList "/s 'C:\Temp\TeamViewer_Settings.reg'"
Please let me know how to call .cmd file as administrator from PowerShell script:
The second line below should open as Administrator from a PowerShell script:
Set-Location "C:\client\service"
Invoke-Item "C:\client\service\_install.cmd"
Then the command prompt should wait after execution. This needs to handle in PowerShell script not possible to write in _install.cmd file.
Batch-scripts runs in CMD.exe, so you need to start a CMD.exe process as admin.
Start-Process -FilePath "C:\Windows\System32\cmd.exe" -ArgumentList "/k","C:\client\service\_install.cmd" -Verb RunAs -Wait
Start-Process is the cmdlet to start a process
-FilePath "C:\Windows\System32\cmd.exe" starts cmd.exe process
-ArgumentList "/k","C:\client\service\_install.cmd" tells cmd to leave the console open after running the script (is this what you wanted? if not, replace with /c so the cmd-window will close when done). The second argument is your script.
-Verb RunAs tells Start-Process to start the process as admin (you will recieve a UAC-window if enabled)
-Wait tells Start-Process to wait until the process is finished. With cmd /k this means after you exited the command prompt. If you've changed that to cmd /c, then it waits until the script is done.
If you need to change the working directory inside the cmd-file, then you need to modify the .cmd, or write a wrapper-script, like:
#echo off
cd /d C:\client\service
C:\client\service\_install.cmd
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
I am trying to execute an external command using powershell, without having the second program to popup, I need to execute this program within the same PowerShell window and output both the log and the errors.
I started with this:
$outcome = Start-Process -Wait -FilePath "cmd.exe" -ArgumentList "dir" -NoNewWindow 2>&1
$outcome
But it doesn't work as expected. I still see the new window popping up with DOS and no redirect at all about the output, the errors and so on.
Am I doing something wrong?
Does this work for you?
$outcome = Invoke-Expression "cmd.exe /c dir"
$outcome
My suggestion is to use the call operator
& cmd.exe /c dir
You can just run it. You're missing "/c".
$outcome = cmd /c dir
With the added complication of start-process, you'd have to save the output to a file.
Start-Process -Wait -FilePath "cmd.exe" -ArgumentList "/c","dir" -NoNewWindow 2>&1 -RedirectStandardOutput cmd.log