Can someone help get this script to work with msu, exe,msi ext?
}
$workingDir = "c:\users" + $me + "\Desktop\Remote_Install"
$inputFile = Read-Host “Where are the IP addresses (file)?”
$inputFile = $workingdir + $inputFile
$iplist = Get-Content $inputFile
$srcFile = Read-Host “Which MSI file shall I load?”
$source = $workingdir + $srcFile
#$parameters = Read-Host “Any parameters?”
$InstallString = ‘msiexec /qn /norestart /lv c:\windows\temp'+$srcFile+’.log /i “C:\windows\temp' + $srcFile + '” '# + $parameters
Write-Host Reading systems from: $inputfile
foreach ($lineitem in $iplist) {
$segments = $lineitem.Split(“,”)
$destination = “\” + $segments[0] + "\c$\windows\temp"
$wmipath = “\” + $segments[0] + “\ROOT\CIMV2:Win32_Process”
Write-host Running: $segments[0]
Write-host
Write-Host Copying from: $source
Write-Host Copying to: $destination
Copy-item $source $destination
Write-Host Done!
Write-Host
Write-Host Connecting via: $wmipath
Write-Host Executing: $InstallString
([WMICLASS]$wmipath).Create($InstallString)
Write-Host Completed: $segments[0]
Write-Host
}
Write-Host Done!
The cmdlet Invoke-Item should help you to make it work for any file type because it launches the default program for the file extension.
For example :
Invoke-Item YourFile.msi
(will open/execute the file with msiexec.exe)
Invoke-Item YourFile.msu
(will open/execute the file using C:\Windows\System32\wusa.exe )
Invoke-Item YourFile.exe
(will execute the file)
You really need to eliminate the prompts; use parameters instead. Also, ditch the Write-Host.; Use Write-Verbose. Here’s a much better method. I just wrote on the fly and I have not tested it at all but even if it doesn’t completely worked, this will get you very close. To do MSUs and EXEs, just modify the ‘msiexec /i /qn…’ remote process creation string.
InstallMSI.ps1
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ValidateScript({Test-Path $_ -PathType 'Leaf' })]
[string]$IpFilePath,
[Parameter(Mandatory)]
[string[]]$MsiFilePath,
[string]$Params
)
begin {
}
process {
foreach ($Computer in $IpFilePath) {
foreach ($Msi in $MsiFilePath) {
if (Test-Connection $Computer -Quiet -Count 1) {
$Dir = 'C$\Windows\Temp'
if (Test-Path "\\$Computer\$Dir")
Copy-Item $Msi "\\$Computer\$Dir" -Force
([WMICLASS]"\\$Computer\Root\CIMV2:Win32_Process").create("msiexec /qn /norestart /lv c:\windows\temp\$Msi.log /i `"C:\windows\temp\$Msi`" $Params")
} else {
Write-Warning "The directory $Dir on $Computer is not available"
}
} else {
Write-Warning "$Computer is offline"
}
}
}
Usage: InstallMsi.ps1 -IpFilePath ‘C:\ips.txt’ -MsiFilePath ‘C:\MSIs\msi1.msi’,‘C:\MSI\msi2.msi’,‘C:\MSI\msi3.msi’ -Params ‘REBOOT=REALLYSUPPRESS’ -Verbose
just a heads up ur missing the ] and you have an extra } at the end
[string$IpFilePath
Thanks Adam, I was wondering is there a way to have the script ask for IP addresses and which file to load?
Execute the script like this: Usage: InstallMsi.ps1 -IpFilePath ‘C:\ips.txt’ -MsiFilePath ‘C:\MSIs\msi1.msi’,‘C:\MSI\msi2.msi’,‘C:\MSI\msi3.msi’ -Params ‘REBOOT=REALLYSUPPRESS’ -Verbose
Replace C:\ips.txt with your text file with IPs in it.