Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, August 22, 2012 12:05 AM
Hello Everyone!
I was wondering if anyone could give me some pointers on how i could go about deploying msi, msp, and exe to remote machines using both from WinRM and WMI approaches.
I'd like to be able to be dynamic so that i can add any UNC path to a read-host and then the name of the file with any switches i may want to add from an additional read-host.
I have seen some variation of different ways to deploy from powershell, but i havent seen one that actually works for remote machines.
Thank you, look forward to speaking with you all.
All replies (11)
Wednesday, August 22, 2012 7:15 PM ✅Answered | 1 vote
Are you gonna check the CPU type before installing, so you can install the correct version.
$ARCH = $ENV:Processor_Architecture If ($ARCH -eq "AMD64") {'Install 64 bit version'} Else {'Install 32 bit version'}Don't forget to mark your posts as answered so they drop off the unanswered post filter.
That's going to require WinRM to run on a remote machine - I don't think the OP wanted to go there.
WMI Method:
$ARCH=(gwmi -Computer localhost -Query "Select OSArchitecture from Win32_OperatingSystem").OSArchitecture
If ($ARCH -eq "32-bit") {'Install 32 bit version'}
Else {'Install 64 bit version'}
Just a humble SysAdmin
Wednesday, August 22, 2012 10:02 PM ✅Answered
I've been experimenting with the WMI create process method and found that, as I suspected, I couldn't get the install package to run from a UNC path - I had to copy the file to the remote computer.
Trying to execute from a UNC path returned error code 2, Access Denied.
However, I tested this code which copies the install file to the remote computer and runs the package with the specified parameters.
The package was installed.
$path = Read-host "Enter the UNC path including name of file>>>" # my example: \\myserver\myshare\software\flash\install_flash_player_ax_11.4.402.265.exe$parameters = Read-host "Enter parameters or switches example: "/qn" -Wait>>>" # my example: -install$packageinstall=(split-path $path -leaf) + ' ' + $parameters # evaluates to: install_flash_player_ax_11.4.402.265.exe -install
$computers = get-content c:\temp\computers.txt
$computers | where{test-connection $_ -quiet -count 1} | ForEach-Object{
copy-item $path "\\$_\c$\temp" # copy install file to the remote machine
$newProc=([WMICLASS]"\\$_\root\cimv2:win32_Process").Create("C:\temp\$packageinstall")
If ($newProc.ReturnValue -eq 0) { Write-Host $_ $newProc.ProcessId } else { write-host $_ Process create failed with $newProc.ReturnValue }
}
Give that a try on a test computer.
Just a humble SysAdmin
Wednesday, August 22, 2012 1:04 AM
What you'll find with most methods is the install package needs to be copied to the remote machine.
You can 'double-hop' with WinRM using CREDSSP but from what I've read - it's not easy to set up...
... copying the install file to the remote machine for local installation is very simple.
Powershell using WMI: (command line will vary - depending on the type of install)
$result = ([WMICLASS]"\$pcname\ROOT\cimv2:Win32_Process").create("Msiexec.create(%22Msiexec) /i <Full Path To Install Package> <Command Line Parameters>")
if($result -eq 0){Write-Host 'Successs'}
Powershell using WinRM: (You do have WinRM set up and working in your environment - don't you?)
invoke-command -computer $computer -scriptblock {start-process -filepath 'c:\windows\system32\cscript.exe' -argumentlist 'c:\temp\software.vbs' -wait}
If you have any difficulty with UAC and other OS security type prompts, I've found that creating a batch file on the remote machine with the install command in it, and executing that with:
invoke-command -computer $computer -scriptblock {start-process -wait -filepath C:\temp\installme.bat}
... circumvents those OS prompts.
installme.bat contains something like 'c:\temp\install_flash_player_ax_11.4.402.265.exe -install' (used this one today to silently update my clients)
If my suggestions don't help you, there are 'a lot' of threads covering the same topic.
Look at 'Related Topics' >> to the right.
Just a humble SysAdmin
Wednesday, August 22, 2012 1:48 PM
Hi RiffyRiot,
I would like to pursue the WMI approach. But i would like some help with the logic if i were to have a list of computers in a text file. I also have the installation located from a file share and would need to know how to leverage this in this approach.
Thank you
Wednesday, August 22, 2012 2:16 PM
Reading your computers from a textfile is easy.
$computers = get-content "path to file"
foreach ($computer in $computers) {
#further logic here
}
Wednesday, August 22, 2012 3:19 PM
Hi JorenD,
Yes, that part is easy, Thanks
Wednesday, August 22, 2012 3:51 PM
Here is the bit for install and uninstall.
Start-Process -FilePath C:\Temp\7z920.msi -ArgumentList "/qn" -Wait#now for uninstallGet-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq "7-Zip 9.20"} | foreach-object -process {$_.Uninstall()}
Don't forget to mark your posts as answered so they drop off the unanswered post filter.
Wednesday, August 22, 2012 6:01 PM | 2 votes
This is what i have tried. But it i get prompts from my side to click ok or cancel.
$computers = get-content c:\temp\computers.txt
$path = Read-host "Enter the UNC path including name of file>>>"
$parameters = Read-host "Enter parameters or switches example: "/qn" -Wait>>>"
foreach ($PC in $Computers) {
Start-process -filepath $path -ArgumentList $parameters
}
Wednesday, August 22, 2012 6:34 PM
Hi RiffyRiot,
I would like to pursue the WMI approach. But i would like some help with the logic if i were to have a list of computers in a text file. I also have the installation located from a file share and would need to know how to leverage this in this approach.
Thank you
Try this...
gc d:\computers.txt | where{test-connection $_ -quiet -count 1} | %{
$newProc=([WMICLASS]"\\$_\root\cimv2:win32_Process").Create("msiexec /I \\server\share\package.msi /qn")
If ($newProc.ReturnValue -eq 0) { Write-Host $_ $newProc.ProcessId } else { write-host $_ Process create failed with $newProc.ReturnValue }
}
Of course, you have to test the command your running to ensure that the package does actualy install silently.
The process starts in the context of the user who started it.
If the package produces a dialog on the screen, the remote user won't be able to see it, the installer will wait for user input which will never happen.
When installing .msi, .msp or .msu, do a msiexec /? to see what the install options are, the switches available should facilitate a silent install.
For a .exe, check the documentation for the package, the developer may have included options for a silent install.
package.exe /? may reveal some command line switches for a silent install - depends on the developer.
Every package/installer is different, even from the same developer. (Adobe Reader and Flash for instance)
Again, test the package with the correct switches to ensure the install is silent (and actually installs!) before you attempt to roll the install out to all the computers.
Just a humble SysAdmin
Wednesday, August 22, 2012 7:00 PM
Are you gonna check the CPU type before installing, so you can install the correct version.
$ARCH = $ENV:Processor_ArchitectureIf ($ARCH -eq "AMD64") {'Install 64 bit version'} Else {'Install 32 bit version'}
Don't forget to mark your posts as answered so they drop off the unanswered post filter.
Thursday, July 11, 2013 5:25 PM
I need help getting this to work, I know this is an old thread, but I am trying to do this very thing, but it is failing.