Parity123
asked on
Powershell: Script to run on all DC
Hello Experts,
I need to run a command on all DCs remotely. Could you please help me with a PowerShell/WinRm script.
Your assistance is much appreciated.
I need to run a command on all DCs remotely. Could you please help me with a PowerShell/WinRm script.
Your assistance is much appreciated.
ASKER
The DC's are running 2008r2. I need to run a command del c:\temp\*.* on all DC
Does remote PowerShell enabled or can be enabled on all DC's?
Or if admin shares are enabled, then you can try..
Or if admin shares are enabled, then you can try..
Import-Module Activedirectory
Get-ADDomainController -Filter * | %{Remove-Item "\\$($_.Name)\c$\temp\*" -recurse}
ASKER
Thanks sub sun. Like the first example you showed, if I want to run multiple commands using invoke-command, how would I modify..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. If I want to include a few lines of Powershell script, can I include it in invoke-command section.
Yes you can include it in the script block as I showed in example...
ASKER
Thanks.
http://ss64.com/ps/invoke-command.html
Example, following code will run Ipconfig /Flushdns command on all DC's
Open in new window