$cs = New-PSSession -ComputerName MACHINE -Credential DOMAIN\admin
Copy-Item -Path C:\Scripts\smart -Destination C:\smart -ToSession $cs
msiexec /i "C:\Smart\SMART.msi" NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK="" LAT_CONTENT="" PRINT_CAPTURE="" INSTALL_DOCCAM_DRIVERS="" CUSTOMER_LOGGING=1 /qnT="" INSTALL_SPU=2 CUSTOMER_LOGGING=0 /qn
Hi,
I'm struggling to get the syntax that runs with the MSI working above - I've worked with switches inside script blocks which invoke commands beforfe successfully but, not with those parameters which are from the program vendors help file.
I also tried:
Start-Process "msiexec.exe" -Argumentlist "/i "C:\smartmsi\SMART.msi" `
NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK="" LAT_CONTENT="" PRINT_CAPTURE="" INSTALL_DOCCAM_DRIVERS="" CUSTOMER_LOGGING=1 /qn
Totally confused how to install using the vendors commands within POwerShell, how can i nest each argument if it's not a switch?
I also tried using Splatter:
$params = '/i', "C:\smartmsi\SMART.msi",
'NB_PROD_KEY=NC-2ADA2-CEAM7-F9RKE', 'ACTIVATE_LICENSE=1',
'/qn'
& msiexec.exe #params
$LastExitCode
No joy - this app will install remotely as a regular install.
Thanks in advance
UPDATE:
Now, i've also tried this:
invoke-command -Session $session -ScriptBlock {
Start-Process -FilePath C:\windows\system32\msiexec.exe `
-ArgumentList "/i `"C:\smart\SMARTSuite.msi`" `"NB_PROD_KEY=NC-2ADA2`" ACTIVATE_LICENSE=1 INSTALL_INK=`"`" LAT_CONTENT=`"`" PRINT_CAPTURE=`"`" INSTALL_DOCCAM_DRIVERS=`"`" CUSTOMER_LOGGING=1 /qn"
}
Still not working. Installer appears for a second then drops off.
You have to escape `" if you want them to be interpreted inside a string which already uses double quotes else you break the string chaining :
Start-Process -FilePath msiexec -ArgumentList "/i `"C:\smartmsi\SMART.msi`" NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK=`"`" LAT_CONTENT=`"`" PRINT_CAPTURE=`"`" INSTALL_DOCCAM_DRIVERS=`"`" CUSTOMER_LOGGING=1 /qn"
You don't have to escape double quotes if the string is surrounded by simple quotes
Related
I use the following example to install some software on a remote computer
I would like to get the exit code back from the MSI so I can determine if successful or if not what the error was
I assumed $result would contain the information I need but I am obviously missing something
Ideas please?
$Result = Invoke-Command -computername MYREMOTEPC -ScriptBlock { Start-Process "msiexec" -ArgumentList "/i C:\tmp\MYSOFTWARE.msi /quiet /norestart" -Wait -Passthru }
Enclose the Start-Process -Passthru command in (...).ExitCode:
$Result = Invoke-Command -computername MYREMOTEPC -ScriptBlock {
(
Start-Process "msiexec" -ArgumentList "/i C:\tmp\MYSOFTWARE.msi /quiet /norestart" -Wait -PassThru
).ExitCode
}
-PassThru instructs Start-Process to output a System.Diagnostics.Process instance representing the launched process, and given that -Wait is also used, its .ExitCode property can be accessed right away.
I have the following PowerShell script, which I am using to get the uninstall string for Google Chrome, and then I want to uninstall it silently. Line 3 in the script will pop up the GUI uninstaller (so it seems like everything is correct thus far), but if I add "/qn" or "/quiet" to the argument list, the uninstall doesn't seem to run at all, even if I let it sit for a couple hours.
What am I missing?
$AppName = "Google Chrome"
$Chrome = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match $($AppName)}
Start-Process -Wait -FilePath MsiExec.exe -Argumentlist "/X",$Chrome.UninstallString.TrimStart("MsiExec.exe /X")
If it's an msi you can use uninstall-package:
get-package *chrome* | uninstall-package -whatif
instead of trying to use /X and remove /X and other things, try the following
# Get the key to uninstall
$chromeUninstall = $Chrome.Pspath.Split("\")[-1]
Start-Process -Wait -FilePath MsiExec.exe -Argumentlist "/X $ChromeUninstall /quiet /norestart"
or even simpler would be,
Start-Process -Wait cmd.exe -ArgumentList "/c msiexec /X $ChromeUninstall /quiet /norestart"
/c - Carries out the command specified by string and then terminates
Note
On my system I get two uninstall strings. You might want to think about looping or selecting first one in the list with the use of [0]
As a precursor to running an installation file on several remote servers, I need to update the Powershell setting MaxMemoryPerShellMB. This requires running a PS session as Administrator on the remote server. I have been trying to run Invoke-Command which then runs a ScriptBlock consisting of a Start-Process command which includes the -Verb RunAs parameter. Nothing seems to work, however.
I have tried with various quoting schemes, single, double, triple, but nothing seems to work.
I've tried running the Start-Process from an Enter-PSSession, with the same results.
Following is the code I'm testing now:
$creds = Get-Credential -Username 'DOMAIN\userID' -Message "Enter Username and Password to access the remote servers."
$ScriptBlock = {
Start-Process -FilePath Powershell.exe -ArgumentList """Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024""" -Verb RunAs -Wait
}
Invoke-Command -ComputerName testsvr01 -Credential $creds -ScriptBlock $ScriptBlock
I should be able to RDP to the remote server and run Get-Item WSMan:\localhost\Shell and have it show the updated value, but the value isn't changed.
When running the code it pauses for a second when the Invoke-Command runs, but other than that, there is no feedback in Powershell.
On the remote server I see the following two Kerberos errors in the System Event log.
0x19 KDC_ERR_PREAUTH_REQUIRED,
0xd KDC_ERR_BADOPTION
Any help is greatly appreciated.
> powershell.exe -?
...
EXAMPLES
...
PowerShell -Command "& {Get-EventLog -LogName security}"
-Command
...
To write a string that runs a Windows PowerShell command, use the format:
"& {<command>}"
where the quotation marks indicate a string and the invoke operator (&)
causes the command to be executed.
So you could try to call Set-Item in the following way:
$ScriptBlock = {
Start-Process -FilePath Powershell.exe -ArgumentList "-Command"," &{ Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024 }" -Verb RunAs -Wait -PassThru
}
$process = Invoke-Command -ComputerName testsvr01 -Credential $creds -ScriptBlock $ScriptBlock
$process.ExitCode
I'm also returning a process object via -PassThru on which you might check the `ExitCode``
Hope that helps
I am trying to install google chrome on a remote server but when I run my script, no error is returned and yet the MSI does not install the software automatically. This script can work locally but not remotely.
Here is the script:
$msi = "MSI path"
Invoke-Command -ComputerName RemoteServer -ScriptBlock {param($msi) Start-Process msiexec.exe -Wait -ArgumentList "/I (MSI Path) /qn /passive"} -ArgumentList $msi
Any help or feedback is appreciated.
I'm not sure, but I think your problem is that you're using the $msi as local and as remote variable. Tow options:
For readonly variables you use the "Using" keyword
See about_remote_variables about details. If you only need to read the value from a variable you can the following:
$msi = "MSI path"
Invoke-Command -ComputerName RemoteServer -ScriptBlock { Start-Process msiexec.exe -Wait -ArgumentList "/I $Using:msi /qn /passive"}
Here you don't need the ArgumentList-parameter of Invoke-Command.
Add a _remote suffix to remote variables
This is only a style I'm using in my scripts to distinguish about local and remote variables.
$msi = "MSI path"
Invoke-Command -ComputerName RemoteServer -ScriptBlock {param($msi_remote) Start-Process msiexec.exe -Wait -ArgumentList "/I $msi_remote /qn /passive"} -ArgumentList $msi
Hope that helps.
Couldnt get my script to work as it is a permission problem on the remote server. It has since been resolved.
Would any of you possibly know why this is not working?
Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit -Command & `"{$outvar1 = 4+4; `"out: $outvar1`"}`"" -Wait
The ultimate purpose for this is so that i can run a script block as another user with the addition of the -Credential option. But i can not get this simple script block to work yet.
Many thanks.
Chris.
Here is somthing that is working:
PS C:\> Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output `$outvar1`"}`"" -Wait
-ArgumentList is an array of strings
$outvar is interpreted so I use `$outvar