Announcement

Collapse
No announcement yet.

Re: Disable network adapter via script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Re: Disable network adapter via script

    Mod Edit: split post from thread:
    http://forums.petri.com/showthread.php?t=24657


    Originally posted by XtaZee View Post
    Hi All,

    I'm looking for a script that disables all network adapters on a remote computer (the computer name is given as a parameter %1)

    I was trying out this script which for now is set for the local machine - but is doesn't disable all the enabled cards (probably because of this line " objItem.Disable "


    here is the script

    Code:
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_NetworkAdapter Where NetEnabled = 'True'")
    
    For Each objItem in colItems 
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "Description: " & objItem.Description
        objItem.Disable
        Wscript.Echo
    Next

    Thanks!!



    Just a little update, here is the script in PowerShell using WMI - it disable all 802.3 nics and after 30 sec enable them again...

    Code:
    # Win32_NetworkAdapter. Disable / Enable Script"  
    # Created by Daniel Klepner 
    
    $filter = "AdapterType = 'Ethernet 802.3' and NetEnabled = 'True'"
    $class = "Win32_NetworkAdapter"
    $namespace = "root\cimv2"
    $strComputer = "."
    
    
    # Find all Active ethernet 802.3 network cards
    $colItems = get-wmiobject -class $class -namespace $namespace -computername $strComputer –filter $filter 
    
    
    
    # Disable  active network cards
    foreach ($objItem in $colItems) {
          write-host $objItem.Description
    	   $objItem.Disable()
    }
    
    
    Start-sleep 30
    
    # Enable active network cards
    foreach ($objItem in $colItems) {
          write-host $objItem.Description
    	   $objItem.Enable()
    }
    now I am working on running it from remote...
    Last edited by Rems; 6th June 2010, 01:30.
Working...
X