Skip to content

Instantly share code, notes, and snippets.

@nshores
Created November 3, 2017 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nshores/115f39ab294bfe62439bfb4f1eb67992 to your computer and use it in GitHub Desktop.
Save nshores/115f39ab294bfe62439bfb4f1eb67992 to your computer and use it in GitHub Desktop.
foreach ($machine in $iplist){
$network = get-vm $machine.Parent | Invoke-VMScript -GuestUser $guestuser -GuestPassword $guestpassword -ScriptText "(gwmi Win32_NetworkAdapter -filter 'netconnectionid is not null').netconnectionid"
$NetworkName = $Network.ScriptOutput
$NetworkName = $NetworkName.Trim()
$machineipvalue = $machine.ip
$machinemaskvalue = $machine.mask
$machinegatewayvalue = $machine.GATEWAY
$machinedns1value = $machine.dns1
$machinedns2value = $machine.dns2
$ip = "netsh interface ip set address ""$NetworkName"" static $machineipvalue $machinemaskvalue $machinegatewayvalue"
$dns1 = "netsh interface ip set dnsservers ""$NetworkName"" static $machinedns1value"
$dns2 = "netsh interface ip add dnsservers ""$NetworkName"" $machinedns2value"
$ip
$dns1
$dns
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment