OS:
Windows Server 2008 R2 English
I use a script to do boot initialization and call the EnableStatic method, but this method always makes an error when it starts up and runs. After logging in to the system, it can run normally when manually executed.
I'm very sorry, my English is very poor. This is from google translation.
startup,log:
manual execution log:
This is my code:
Function WaitNICExist {
$NIC = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where {$_.IPEnabled -eq $true}
if ($NIC -eq $null) {
Start-Sleep -sec 3
Write-Host "Waiting another 3 sec for NIC"
$NIC = WaitNICExist
return $NIC
} else {
return $NIC
}
}
$IPS = @()
$MASKS = @()
$IPS += $ip
$MASKS += $subnet
Start-Transcript
$NIC = WaitNICExist
Write-Host "3333"
ps
Write-Host "3333"
$NIC.EnableStatic($IPS, $MASKS)
$NIC.SetGateways($gateway)
#$NIC.SetDNSServerSearchOrder($dns)