Skip to content

Instantly share code, notes, and snippets.

@rybons
Last active March 15, 2024 23:04
Show Gist options
  • Save rybons/a063a47bcecc51afe198bba5d4cef6d4 to your computer and use it in GitHub Desktop.
Save rybons/a063a47bcecc51afe198bba5d4cef6d4 to your computer and use it in GitHub Desktop.
remote winrm script example
$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