Last active
March 15, 2024 23:04
-
-
Save rybons/a063a47bcecc51afe198bba5d4cef6d4 to your computer and use it in GitHub Desktop.
remote winrm script example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ips = $args[0] | |
Foreach ($ip in $ips) { | |
$Username = '{0}\Administrator' -f $ip | |
$Password = '${password}' | |
$pass = ConvertTo-SecureString -AsPlainText $Password -Force | |
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass | |
Set-Item wsman:\localhost\client\trustedhosts $ip -Confirm:$false -Force | |
Invoke-Command -ComputerName $ip -ScriptBlock { Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) } -credential $Cred | |
Invoke-Command -ComputerName $ip -ScriptBlock { C:/ProgramData/chocolatey/choco install git -y } -credential $Cred | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment