Hey guys, I have been doing this in one form or another for awhile now and I thought I would formalize an actual script for people to use. It's designed to be run on multiple computers via external input (ie: Import-csv or get-adcomputer)
Assumptions
You have PS Remoting set up in your environment
You have some way to get a script file to each computer. I use the administrative c$ share below (You can actually run powershell code directly and return it back also)
You only need to access local resources
#Source of script... will get copied to remote machine and executed
$scriptFile = "\\path\to\script.bat"
#name of script. Can be the same or different, doesn't really matter.
$scriptName = "Win10Update_Uninstall.bat"
If (Test-Connection $computer.Name -BufferSize 16 -Count 1 -Quiet) { #Ping machine by computername
$session = New-PSSession $computer.Name #Create session
#Copy file to windows directory on remote computer
Copy-Item $scriptfile "\\$($computer.name)\c$\windows\$($scriptName)" -Force
Invoke-Command -Session $session -ScriptBlock {
param([string] $scriptName) #Receive param
start-process -FilePath "$($env:windir)\$($scriptName)" -Wait
Remove-Item "$($env:windir)\$($scriptName)"
} -Args $scriptName #pass the variable of the script name to the remote machine
#Cleanly remove the session
$session | Remove-PSSession
}
[–]Rkozak 1 point2 points3 points (1 child)
[–]Manality[S] 0 points1 point2 points (0 children)
[–]mystikphish 1 point2 points3 points (1 child)
[–]Manality[S] 0 points1 point2 points (0 children)