Disable not connected NIC's

23 Feb 2012 by Ryan Ververs-Bijkerk

Category:

    PowerShell

Disable not connected NIC's

My colleague Niels Geursen called me and asked if I could help him with some scripting. At his customer, monitoring software generates a pop-up window with a warning about some NIC’s that were not connected. By disabling the NIC’s the error does not appear. To avoid manual actions on all Citrix servers he wanted to created a script to collect all disconnected NIC’s and disable them. To help Niels I wrote the following script.

# Collect Disconnected NIC's

$NIC = Get-WmiObject -Namespace "root\cimv2" -Query "select * from `
Win32_NetworkAdapter WHERE PhysicalAdapter = 'True'`
and NetConnectionStatus = '7'"

IF ($NIC -like "") {Exit}
# Show Results is optional.

$NIC | Select-Object NetConnectionID, Name

# Disable NIC's

$objNIC = $NIC.Count

IF ($objNIC -like "") {
$NIC.disable() | Out-Null
} Else {

$i = 0

DO {
$disNIC = $NIC[$i] ; $i++

$disNIC.Disable() | Out-Null
} While ($i -le $objNIC -1 )
}
Tags:
    nic
    powershell
    scripting
Ryan Ververs-Bijkerk
Written by Ryan Ververs-Bijkerk

Ryan is currently a Technical Evangelist at RawWorks focused on the End-User Computing area. Ryan is primarily focusing on the user experience in centralized desktop environments.

Search

    Follow me

    Community