Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinblumenfeld/ff54b2aeea7b2556390a05ad8ae0d325 to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/ff54b2aeea7b2556390a05ad8ae0d325 to your computer and use it in GitHub Desktop.
foreach ($comp in $computers) {
New-PSSession -ComputerName $comp -Credential $Credential
$TargetSess = (Get-PSSession -ComputerName $comp -Credential $Credential | where {$_.State -eq 'opened'})
$destination = "c:\scripts\R"
Copy-Item \\source\R\* -Destination $destination -ToSession $TargetSess -Force
$ScriptBlock = {
cd "C:\scripts\R";
. .\Remove-PreviousOfficeInstalls.ps1
Remove-PreviousOfficeInstalls
}
Invoke-Command -SessionName $TargetSess -ScriptBlock $ScriptBlock -AsJob -JobName $comp -Verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment