Saturday, 7 February 2009

Disable-NetworkCard.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Disables active network cards 
  4. .DESCRIPTION 
  5.     This script looks at each network card that is currently IP enabled, and 
  6.     disables it by releasing the DHCP Lease. To re-enable the network interrace, 
  7.     you just run IPCONFIG /RENEW. 
  8.      
  9.     This script is an MSDN Sample, rewritten using PowerShell 
  10. .NOTES 
  11.     File Name  : Disable-NetworkCard.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell V2 CTP3 
  14. .LINK 
  15.     PowerShell script posted to: 
  16.        http://pshscripts.blogspot.com/2009/02/disable-networkcardps1.html
  17.     Original MSDN Sample at: 
  18.        http://msdn.microsoft.com/en-us/library/aa394595(VS.85).aspx 
  19. .EXAMPLE 
  20.     PSH [C:\foo]: .\Disable-NetworkCard.ps1 
  21.     Releasing lease on: [00000006] Broadcom NetXtreme Gigabit Ethernet 
  22.     Releasing lease on: [00000012] Microsoft Virtual Network switch Adapte 
  23. #> 
  24.    
  25. ### 
  26. #  Starting Script 
  27. ### 
  28.   
  29. $Computer = "." 
  30. $net = Get-WMIObject -class Win32_NetworkAdapterConfiguration -ComputerName $computer 
  31. $netenabled = $net | where {$_.IPenabled} 
  32. foreach ($NetCard in $netenabled) { 
  33.     "Releasing lease on: {0}" -f $netcard.caption 
  34.     $netcard.ReleaseDHCPLease() 
  35. # End of Script 

1 comment:

mrTomahawk said...

I wouldn't really consider a script which disabled the NIC, rather a script which releases an IP from an NIC. A disabler would truely disable the device