Hello again Scripting Guys,
I have a script that lets you install software on remote computers. It's a little slow when using against a long list of computers, but it works. I do not have SCCM available, so I have always used free utilities (psexec) to install / upgrade /remove third party software. I am trying to transition completely from sysinternals suite utilities to powershell, since PSExec send credentials in clear text. I've been working on install and remove scripts for .exe / .msi software. It would be nice to have one script that could do all but I'm nowhere near accomplishing this yet.
Question is; I want to improve this script by giving me some sort of feedback as to success / failure, as well as speed up the process if possible. I liked the get-wmiobject -class win32_Product commands since they tell me return codes, but couldn't get these to work. PSExec tells me a PID which I can at least watch on the remote computer to see how long the process takes to complete. I know there are commands like Write-host but I'm not sure how to use this with the invoke-command start-process to provide me with feedback.
$computers = Get-Content 'C:\computerlist.txt'
$sourcefile = '\\server\folder\java.exe'
$process = 'java.exe'
$arglist = '/s /norestart'
foreach ($computer in $computers){Write-Host "Processing computer: $computer" -ForegroundColor green
Try{
$destinationFolder="\\$computer\C$\Temp"
if(!(Test-Path -path $destinationFolder)){
New-Item $destinationFolder -Type Directory -Force -ErrorAction Inquire }
Copy-Item -Path $sourcefile -Destination $destinationFolder -Force -ErrorAction Inquire
Invoke-Command -ComputerName $computer -ScriptBlock {Start-Process "C:\Temp\$using:process" -ArgumentList ($using:arglist) -verb runas -Wait -ErrorAction Inquire}}
Catch{Write-Host $_ -ForegroundColor red -BackgroundColor white}
}