Morning folks (UK Time)
I have looked everywhere and i cannnot find anything to do with this admittedly im fairly new so i’l explain the problem first…then my potential solution…
I am writing a script to install Visio silently onto remote machines. i have tested this out on one machine and it works fine and tweaked my coding for it to work on two machines. I am doing this via WINRM and sessions.
The problem im facing is that AFAIK theres is a maximum of 5 remote sessions at a time? which isnt so bad as i think if i ran multiple sessions id kill my network. So im happy to work say 98 computers in batches of 5.
SO my solution was to take an array of say 98 computers and work it in batches of 5 creating sessions for each machine installing Visio and waiting until setup.exe has finished before moving onto the next machine…
Problems :
I dont know how to work an array in batches…
if one machine takes longer than the other or fails the code might get stuck waiting for setup.exe to finish when it hasnt started…I’l post my two codes to show you sort of what ive done…
Original script was used on a one to one basis where WINRM isnt enabled (hoping to enable this for through GPO)
sorry if its awfully written!
Current script to work with parallel sessions (not finished)
$computers = @(“GB002783”,“GB002824”)
$sessions = new-PSSession -computername $computers
invoke-command -session $sessions -scriptblock {$net = new-object -ComObject WScript.Network}
invoke-command -session $sessions -scriptblock {$drive = ls function:[g-z]: -n | ?{ !(test-path $) } | select -first 1}
invoke-command -session $sessions -scriptblock {$net.MapNetworkDrive($drive, “\Mapped Network Location”, $false, “Domain\Username”, “Password”)}
invoke-command -session $sessions -scriptblock {set-location $drive}
$program = “Setup”
Previous script for installing Visio and waiting for setup.exe
Function Start-InstallVisio($computers){
foreach ($comp in $computers){
$cpath = “\”+($comp)+“\c$\Installer”
If (Test-Connection -comp ($comp) -count 1 -quiet) {
copy-item -path “Mapped Network Location\wirm.bat” -destination $cpath -force
c:\pstools\psexec \$comp -u administrator -p $passadmin “c:\installer\wirm.bat”
remove-item $cpath\wirm.bat -force
$s = new-PSSession $comp
invoke-command -session $s -scriptblock {$net = new-object -ComObject WScript.Network}
invoke-command -session $s -scriptblock {$drive = ls function:[g-z]: -n | ?{ !(test-path $) } | select -first 1}
invoke-command -session $s -scriptblock {$net.MapNetworkDrive($drive, “\Mapped Network Location\Visio 2010”, $false, “Domain\Username”, “Password”)}
invoke-command -session $s -scriptblock {set-location $drive}
invoke-command -session $s -scriptblock {.\setup.exe}
$program = “Setup”
get-service remoteregistry -computername $comp | set-service -status running
#$process = Invoke-WmiMethod -Class Win32_Process -Name create -ArgumentList $Program -ComputerName $computer
#$processId = $process.ProcessId
$runningCheck = { (Get-WmiObject -Class Win32_Process -ComputerName $comp -ErrorAction SilentlyContinue) | ? { ($_.ProcessName -eq “$program.exe”) } }
$Time = [System.Diagnostics.Stopwatch]::StartNew()
$CurrentTime = $Time.Elapsed
while ($null -ne (& $runningCheck))
{Write-Host “$([string]::Format(”`rUpdate: $program Is Still Running…Please Wait! Time Running: {0:d2}:{1:d2}“,$CurrentTime.minutes,$CurrentTime.seconds))”
Start-Sleep -s 30
$CurrentTime = $Time.Elapsed
}
Remove-PSSession $s
}}}