Hi Everyone, Happy Friday.
I have this script, which works, it disables both NIC settings I need it to. The problem I have is, after the 2nd setting gets disabled, you lose connection to the server for a few seconds, and the script just hangs for a long period of time. Is there anyway to keep the script moving along to the next server, after the 2 settings have been set?
# Get the list of servers from the text file
$servers = Get-Content "C:\temp\servers.txt"
# Loop through each server
foreach ($server in $servers) {
Write-Host "Disabling NIC power management on $server"
# Disable NIC power management using the Set-NetAdapterPowerManagement cmdlet
Invoke-Command -ComputerName $server -ScriptBlock {
$net = Get-NetAdapter
$NICs = Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeID = '0' AND PhysicalAdapter = 'true' AND NOT Description LIKE '%wireless%' AND NOT Description LIKE '%virtual%' AND NOT Description LIKE '%WiFi%' AND NOT Description LIKE '%Bluetooth%'"
Foreach ($NIC in $NICs) {
$powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | Where-Object { $_.InstanceName -match [regex]::Escape($nic.PNPDeviceID) }
If ($powerMgmt.Enable -eq $True) {
$powerMgmt.Enable = $False
$powerMgmt.psbase.Put()
}
Set-NetAdapterAdvancedProperty -Name $net.Name -DisplayName "Interrupt Moderation" -DisplayValue "Disabled"
}
}
}
Here is sample output:
Disabling NIC power management on server
WARNING: Attempting to reconnect to server...been interrupted. Attempting to reconnect for up to 4 minutes...
WARNING: TheInvoke-Command: C:\Temp\ITScript\Windows\Modify-Nic.ps1:12
Line |
12 | Invoke-Command -ComputerName $server -ScriptBlock {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Object reference not set to an instance of an object.
PSComputerName : server
RunspaceId : ce668f8f-0cb5-44bf-a12a-60bb1b3d10a6
Path : \\localhost\root\wmi:MSPower_DeviceEnable.InstanceName="PCI\\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\\005056FFFFA
6C05A00_0"
RelativePath : MSPower_DeviceEnable.InstanceName="PCI\\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\\005056FFFFA6C05A00_0"
Server : localhost
NamespacePath : root\wmi
ClassName : MSPower_DeviceEnable
IsClass : False
IsInstance : True
IsSingleton : False
Disabling NIC power management on server
WARNING: The network connection to server has been interrupted. Attempting to reconnect for up to 4 minutes...
WARNING: Attempting to reconnect to server...
WARNING: The network connection to server has been restored.
Thanks!