none
Disabling Wireless Adapter

    Question

  • I want to run a Powershell Startup Script to disable the Wireless adapters on some systems. I thought I'd want to get some WMI stuff

    Get-WmiObject -Class Win32_NetworkAdapter -Filter "Name = 'Intel(R) Centrino(R) Advanced-N 6205'

    Then run netsh to disable it

    netsh interface set interface "Wireless Network Connection" DISABLED

    After looking at this I wondered why not just run the

    netsh interface set interface "Wireless Network Connection" DISABLED

    I don't really need the Get-WmiObject do I?


    Orange County District Attorney

    Tuesday, March 05, 2013 11:26 PM

Answers

  • Hi,

    Have you tried what RiffyRiot suggested?

    Please also refer below article:

    Disable WiFi with PowerShell

    http://msmvps.com/blogs/robfarley/archive/2008/11/18/disable-wifi-with-powershell.aspx

    Use PowerShell 3.0 to Work with Network Adapters

    http://blogs.technet.com/b/heyscriptingguy/archive/2012/09/04/use-powershell-3-0-to-work-with-network-adapters.aspx

    Hope this helps.

    Regards,

    Yan Li

    If you have any feedback on our support, please click here .


    Cataleya Li
    TechNet Community Support

    Monday, March 11, 2013 5:51 AM
  • Here are a couple of scripts ( ps and vbscript )  that can be used on a dell bios.. You could adapt it to disable the wireless adapter in the bios if you want  ..
    ( pcombobox app is on www.justcode.ca  )

    Powershell ( may require dell client management agent )
    ########################################

    (gwmi DCIM_BIOSService -namespace root\dcim\sysman).SetBIOSAttributes($null,$null,"Wake On LAN","4")
    Possible values are:
    1 - Disable
    2 - Add-in
    3 - On board
    4 - LAN
    5 - PXE boot enable
    6 - LAN or WLAN
    7 - WLAN only
    .
    .

    vbscript
    ###############

    '**********************************************************************
    '  Set Dell Bios items
    '  Requires that the Dell Client Management software is installed 
    '**********************************************************************

    '**********************************************************************
    'Dell DCIM values
    '**********************************************************************
    ' Wake on LAN values

    '**********************************************************************
    'Enables or Disables Multiple CPU Core support on next boot.
    'Possible values are:
    '1 = Other
    '2 = Unsupported
    '3 = Enabled
    '4 = Disabled
    'The actual values are not the above, but the below - Paul Jorgensen - Nov 2011 ( Dell gx760 )
    '1 = Disabled
    '2 = Enabled

    '**********************************************************************
    'AC Power Recovery Mode

    '1 = ?
    '2 = ?
    '**********************************************************************

    '**********************************************************************
    'Processor Logical Processor(HyperThreading)
    '1 = ?
    '2 = ?
    '**********************************************************************

    Option Explicit

    '*** Declare variables
    Dim strNameSpace
    Dim strComputerName
    Dim strClassName
    Dim strKeyValue
    Dim objWMIService
    Dim ColSystem
    Dim objInstance
    Dim oInParams
    Dim returnValue
    Dim strAttributeName(2)
    Dim strAttributeValue(2)
    Dim strAuthorizationToken

    Dim psDellBios
    Dim WshShell, objWshScriptExec
    Dim psAttribute
    Dim psValue
    Dim pbAttributeFound

    Set WshShell = WScript.CreateObject("WScript.Shell")

    '*** Check that the right executable was used to run the script
    '*** and that all parameters were passed
    If (LCase(Right(WScript.FullName, 11)) = "wscript.exe" ) Or _
        (WScript.Arguments.Count < 1) Then
        Call Usage()
        WScript.Quit
    End If

    '*** request combobox input as to which bios setting should be updated
    psDellBios = GetComboInput("pcombobox.exe /p:WakeOnLAN,EnableDualCPU")
    WScript.Echo("This is setting ->" & psDellBios)

    '*** Initialize variables
    strNameSpace = "root\dcim\sysman"
    strComputerName = WScript.Arguments(0)
    strClassName = "DCIM_BIOSEnumeration"

    '*** Set Variables based on combobox selection
    If psDellBios = "WakeOnLAN" Then 
    psAttribute = "Wake On LAN"
    psValue = "4"
    End If
    If psDellBios = "EnableDualCPU" Then
    psAttribute = "Multiple CPU Cores"
    psValue = "1"             ' see value notes at top of script
    End If

    '*** Retrieve the instance of DCIM_BIOSEnumeration class for the TPM
    Set objInstance = GetObject("WinMgmts:{impersonationLevel=impersonate," &_
        "AuthenticationLevel=pktprivacy}\\" & strComputerName & "\" &_
    strNameSpace)

    '*** print out attribute if found
    Set ColSystem = objInstance.execquery("Select * from " & strClassName)
    For Each objInstance In ColSystem
    '*** Check every instance
      'iTKVal = objInstance.Properties_.Item("CurrentValue").Value(0)
    '*** Auto On Hour and Auto On Minutes don't have PossibleValues and PossibleValuesDescription properties
    If (objInstance.AttributeName = psAttribute)  Then
    WScript.Echo("Specified Attribute found " & objInstance.AttributeName & ", " & ( objInstance.CurrentValue(0) ) & VbCrLf )
    pbAttributeFound = True
    End If

    Next


        strClassName = "DCIM_BIOSService"
        strAttributeName(0) = psAttribute    ' Wake on LAn or Multi Core CPU, see psAttribute in query section above
    WScript.Echo("strAttributeName-> " & strAttributeName(0))
      strAttributeValue(0) = psValue
        WScript.Echo("strValue-> " & strAttributeValue(0))
        strAuthorizationToken = ""
     
        '*** Retrieve the instance of DCIM_BIOSService class 
    Set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate," &_
            "AuthenticationLevel=pktprivacy}\\" & strComputerName & "\" &_
    strNameSpace )

        Set ColSystem=objWMIService.execquery ("Select * from " & strClassName)

        For Each objInstance In ColSystem    
            Set oInParams = objInstance.Methods_("SetBIOSAttributes").InParameters.SpawnInstance_
            oInParams.AttributeName = strAttributeName
            oInParams.AttributeValue = strAttributeValue
            oInParams.AuthorizationToken = strAuthorizationToken
            Set returnValue = objInstance.ExecMethod_("SetBIOSAttributes", oInParams)
            Exit For
        Next
    'End If

    '*** If any errors occurred, let the user know
    If Err.Number <> 0 Then
        WScript.Echo "Enabling Wake On LAN failed."
    End If



    '*** Sub used to display the correct usage of the script
    Sub Usage()
    Dim strMessage
    strMessage = "incorrect syntax. You should run: " & vbCRLF & _
        "cscript.exe /nologo SampleWakeOnLAN.vbs <systemname>"
    WScript.Echo strMessage



    End Sub

    Function GetComboInput(cbparam)

    Dim sTempPath, sTempResult, sTempExitCode
       
    sTempPath = cbparam
    WScript.Echo sTempPath
    Err.Clear
    'WshShell.run sTempPath, WINDOWNORMAL, True
    Set objWshScriptExec = WshShell.Exec(sTempPath)
    ' ***** BELOW - **  USE RegRead to read reg return value **** !!!!
    'wscript.Echo WshShell.RegRead(testregpath)
    'WScript.Echo Err.Number
    Do While objWshScriptExec.Status = 0
    WScript.Sleep 100
    'WScript.Echo "this is the status code" & objWshScriptExec.Status
    Loop
    '**** if item was not picked from combobox, take action based on errorlevel
    sTempExitCode = objWshScriptExec.ExitCode
    If (objWshScriptExec.ExitCode = 0 Or objWshScriptExec.ExitCode = 100 Or objWshScriptExec.ExitCode = 102 Or objWshScriptExec.ExitCode = 101) Then
    'If(objWshScriptExec.ExitCode > 20 )Then 
    Select Case sTempExitCode
    Case 0
    WScript.Echo "User clicked cancel"
    WScript.Quit(0)
    Exit Function
    Case 100   
    WScript.Echo "User clicked return abort"
    WScript.Quit(100)
    Exit Function
    Case 101
    WScript.Echo "User clicked ok with NULL item"
    WScript.Quit(101)
    Exit Function
    Case 102
    WScript.Echo "User clicked ok with data entry"
    'WScript.Echo " result is " & 
    GetComboInput = WshShell.RegRead("HKCU\Software\Green-Frog-Software\pComboBox\RData\PComboBox")
    WScript.Echo " GetComboInput is " & GetComboInput
    Exit Function
    Case Else
    End Select  
         
    End If

    'WScript.Echo objWshScriptExec.ExitCode
    '**** return the error value
    '*****ACTUALLY - parse "cbparam" using the exitcode to return the 
    '***** the string required rather then run another function
    '***** or run a generic function from here...
    '***** this will make the function single line usage 
    '***** which is way more script friendly
    sTempResult = pfParseResult(cbparam, objWshScriptExec.ExitCode)
    'WScript.Echo sTempResult
    GetComboInput = sTempResult
         
    End Function

    ' ***********************************************************************
    ' ** Application:  VB MapDrives
    ' ** Function:  pfParseResult
    ' ** Purpose:   match the errorlevel returned to the input string desired
    ' ** Update:    
    ' ** Date: Jan 6 2009
    ' ** Author:    Paul Jorgensen
    ' ***********************************************************************
       
    Function pfParseResult(cbparam, pi_Result)

    Dim sTempPath, sSplitFirst, piLen
    Dim paParseArray
       
    sTempPath = cbparam
    'WScript.Echo sTempPath
    Err.Clear
       
    piLen = Len(cbparam)
    If (piLen > 17) Then
    sSplitFirst = Right(cbparam, piLen - 17)    ' 17 = 3 for /p: and 14 for pcombobox.exe with spaces
    End If
    'WScript.Echo "this is sSplitFirst" & sSplitFirst
       
    paParseArray = Split(sSplitFirst, ",", -1, 0)     ' string, delimiter, count -1 = all, binary(0) or text (1)
    'WScript.echo CrLf
    'WScript.echo paParseArray(0)
    'WScript.echo CrLf
    'WScript.echo paParseArray(1)
       
    ' ie a valid selection was returned from GetComboInput, so use the return code ( pi_Result) which represents the item
    ' selected to select the item from the paParseArray which is the cbparam parameter minus the exe and the /p: with
    ' the /p: parameters split into the paParseArray ( ie D,L,R,S,V.... )
    pfParseResult = paParseArray(pi_Result - 1)
       
               
    'Do While objWshScriptExec.Status =0
    'WScript.Sleep 100
    'WScript.Echo "this is the status code" & objWshScriptExec.Status
    'Loop

       


         
    End Function


    just code, no beer...although that would probably help..


    Tuesday, March 12, 2013 2:55 AM

All replies

  • You can do it either way - your preference.

    The WMI object has a Disable method you can use (depending on OS - not XP or lower):

    $myadapter=Get-WmiObject -Class Win32_NetworkAdapter -Filter "Name = 'Intel(R) Centrino(R) Advanced-N 6205'"

    $myadapter.Disable() #| out-null

    You can test the adapters status with: $myadatpter.NetEnabled (depending on OS - not XP or lower)

    Admittedly, using netsh with "Wireless Network Connection" would be easier than catering for several different wireless devices.


    Inspired by Carlsberg.

    Wednesday, March 06, 2013 12:16 AM
  • Do you want to disable it in the BIOS also or just in the OS?

    Paul Jorgensen www.justcode.ca

    Wednesday, March 06, 2013 1:31 AM
  • Just in the OS.

    Orange County District Attorney

    Wednesday, March 06, 2013 3:12 PM
  • Hi,

    Have you tried what RiffyRiot suggested?

    Please also refer below article:

    Disable WiFi with PowerShell

    http://msmvps.com/blogs/robfarley/archive/2008/11/18/disable-wifi-with-powershell.aspx

    Use PowerShell 3.0 to Work with Network Adapters

    http://blogs.technet.com/b/heyscriptingguy/archive/2012/09/04/use-powershell-3-0-to-work-with-network-adapters.aspx

    Hope this helps.

    Regards,

    Yan Li

    If you have any feedback on our support, please click here .


    Cataleya Li
    TechNet Community Support

    Monday, March 11, 2013 5:51 AM
  • Here are a couple of scripts ( ps and vbscript )  that can be used on a dell bios.. You could adapt it to disable the wireless adapter in the bios if you want  ..
    ( pcombobox app is on www.justcode.ca  )

    Powershell ( may require dell client management agent )
    ########################################

    (gwmi DCIM_BIOSService -namespace root\dcim\sysman).SetBIOSAttributes($null,$null,"Wake On LAN","4")
    Possible values are:
    1 - Disable
    2 - Add-in
    3 - On board
    4 - LAN
    5 - PXE boot enable
    6 - LAN or WLAN
    7 - WLAN only
    .
    .

    vbscript
    ###############

    '**********************************************************************
    '  Set Dell Bios items
    '  Requires that the Dell Client Management software is installed 
    '**********************************************************************

    '**********************************************************************
    'Dell DCIM values
    '**********************************************************************
    ' Wake on LAN values

    '**********************************************************************
    'Enables or Disables Multiple CPU Core support on next boot.
    'Possible values are:
    '1 = Other
    '2 = Unsupported
    '3 = Enabled
    '4 = Disabled
    'The actual values are not the above, but the below - Paul Jorgensen - Nov 2011 ( Dell gx760 )
    '1 = Disabled
    '2 = Enabled

    '**********************************************************************
    'AC Power Recovery Mode

    '1 = ?
    '2 = ?
    '**********************************************************************

    '**********************************************************************
    'Processor Logical Processor(HyperThreading)
    '1 = ?
    '2 = ?
    '**********************************************************************

    Option Explicit

    '*** Declare variables
    Dim strNameSpace
    Dim strComputerName
    Dim strClassName
    Dim strKeyValue
    Dim objWMIService
    Dim ColSystem
    Dim objInstance
    Dim oInParams
    Dim returnValue
    Dim strAttributeName(2)
    Dim strAttributeValue(2)
    Dim strAuthorizationToken

    Dim psDellBios
    Dim WshShell, objWshScriptExec
    Dim psAttribute
    Dim psValue
    Dim pbAttributeFound

    Set WshShell = WScript.CreateObject("WScript.Shell")

    '*** Check that the right executable was used to run the script
    '*** and that all parameters were passed
    If (LCase(Right(WScript.FullName, 11)) = "wscript.exe" ) Or _
        (WScript.Arguments.Count < 1) Then
        Call Usage()
        WScript.Quit
    End If

    '*** request combobox input as to which bios setting should be updated
    psDellBios = GetComboInput("pcombobox.exe /p:WakeOnLAN,EnableDualCPU")
    WScript.Echo("This is setting ->" & psDellBios)

    '*** Initialize variables
    strNameSpace = "root\dcim\sysman"
    strComputerName = WScript.Arguments(0)
    strClassName = "DCIM_BIOSEnumeration"

    '*** Set Variables based on combobox selection
    If psDellBios = "WakeOnLAN" Then 
    psAttribute = "Wake On LAN"
    psValue = "4"
    End If
    If psDellBios = "EnableDualCPU" Then
    psAttribute = "Multiple CPU Cores"
    psValue = "1"             ' see value notes at top of script
    End If

    '*** Retrieve the instance of DCIM_BIOSEnumeration class for the TPM
    Set objInstance = GetObject("WinMgmts:{impersonationLevel=impersonate," &_
        "AuthenticationLevel=pktprivacy}\\" & strComputerName & "\" &_
    strNameSpace)

    '*** print out attribute if found
    Set ColSystem = objInstance.execquery("Select * from " & strClassName)
    For Each objInstance In ColSystem
    '*** Check every instance
      'iTKVal = objInstance.Properties_.Item("CurrentValue").Value(0)
    '*** Auto On Hour and Auto On Minutes don't have PossibleValues and PossibleValuesDescription properties
    If (objInstance.AttributeName = psAttribute)  Then
    WScript.Echo("Specified Attribute found " & objInstance.AttributeName & ", " & ( objInstance.CurrentValue(0) ) & VbCrLf )
    pbAttributeFound = True
    End If

    Next


        strClassName = "DCIM_BIOSService"
        strAttributeName(0) = psAttribute    ' Wake on LAn or Multi Core CPU, see psAttribute in query section above
    WScript.Echo("strAttributeName-> " & strAttributeName(0))
      strAttributeValue(0) = psValue
        WScript.Echo("strValue-> " & strAttributeValue(0))
        strAuthorizationToken = ""
     
        '*** Retrieve the instance of DCIM_BIOSService class 
    Set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate," &_
            "AuthenticationLevel=pktprivacy}\\" & strComputerName & "\" &_
    strNameSpace )

        Set ColSystem=objWMIService.execquery ("Select * from " & strClassName)

        For Each objInstance In ColSystem    
            Set oInParams = objInstance.Methods_("SetBIOSAttributes").InParameters.SpawnInstance_
            oInParams.AttributeName = strAttributeName
            oInParams.AttributeValue = strAttributeValue
            oInParams.AuthorizationToken = strAuthorizationToken
            Set returnValue = objInstance.ExecMethod_("SetBIOSAttributes", oInParams)
            Exit For
        Next
    'End If

    '*** If any errors occurred, let the user know
    If Err.Number <> 0 Then
        WScript.Echo "Enabling Wake On LAN failed."
    End If



    '*** Sub used to display the correct usage of the script
    Sub Usage()
    Dim strMessage
    strMessage = "incorrect syntax. You should run: " & vbCRLF & _
        "cscript.exe /nologo SampleWakeOnLAN.vbs <systemname>"
    WScript.Echo strMessage



    End Sub

    Function GetComboInput(cbparam)

    Dim sTempPath, sTempResult, sTempExitCode
       
    sTempPath = cbparam
    WScript.Echo sTempPath
    Err.Clear
    'WshShell.run sTempPath, WINDOWNORMAL, True
    Set objWshScriptExec = WshShell.Exec(sTempPath)
    ' ***** BELOW - **  USE RegRead to read reg return value **** !!!!
    'wscript.Echo WshShell.RegRead(testregpath)
    'WScript.Echo Err.Number
    Do While objWshScriptExec.Status = 0
    WScript.Sleep 100
    'WScript.Echo "this is the status code" & objWshScriptExec.Status
    Loop
    '**** if item was not picked from combobox, take action based on errorlevel
    sTempExitCode = objWshScriptExec.ExitCode
    If (objWshScriptExec.ExitCode = 0 Or objWshScriptExec.ExitCode = 100 Or objWshScriptExec.ExitCode = 102 Or objWshScriptExec.ExitCode = 101) Then
    'If(objWshScriptExec.ExitCode > 20 )Then 
    Select Case sTempExitCode
    Case 0
    WScript.Echo "User clicked cancel"
    WScript.Quit(0)
    Exit Function
    Case 100   
    WScript.Echo "User clicked return abort"
    WScript.Quit(100)
    Exit Function
    Case 101
    WScript.Echo "User clicked ok with NULL item"
    WScript.Quit(101)
    Exit Function
    Case 102
    WScript.Echo "User clicked ok with data entry"
    'WScript.Echo " result is " & 
    GetComboInput = WshShell.RegRead("HKCU\Software\Green-Frog-Software\pComboBox\RData\PComboBox")
    WScript.Echo " GetComboInput is " & GetComboInput
    Exit Function
    Case Else
    End Select  
         
    End If

    'WScript.Echo objWshScriptExec.ExitCode
    '**** return the error value
    '*****ACTUALLY - parse "cbparam" using the exitcode to return the 
    '***** the string required rather then run another function
    '***** or run a generic function from here...
    '***** this will make the function single line usage 
    '***** which is way more script friendly
    sTempResult = pfParseResult(cbparam, objWshScriptExec.ExitCode)
    'WScript.Echo sTempResult
    GetComboInput = sTempResult
         
    End Function

    ' ***********************************************************************
    ' ** Application:  VB MapDrives
    ' ** Function:  pfParseResult
    ' ** Purpose:   match the errorlevel returned to the input string desired
    ' ** Update:    
    ' ** Date: Jan 6 2009
    ' ** Author:    Paul Jorgensen
    ' ***********************************************************************
       
    Function pfParseResult(cbparam, pi_Result)

    Dim sTempPath, sSplitFirst, piLen
    Dim paParseArray
       
    sTempPath = cbparam
    'WScript.Echo sTempPath
    Err.Clear
       
    piLen = Len(cbparam)
    If (piLen > 17) Then
    sSplitFirst = Right(cbparam, piLen - 17)    ' 17 = 3 for /p: and 14 for pcombobox.exe with spaces
    End If
    'WScript.Echo "this is sSplitFirst" & sSplitFirst
       
    paParseArray = Split(sSplitFirst, ",", -1, 0)     ' string, delimiter, count -1 = all, binary(0) or text (1)
    'WScript.echo CrLf
    'WScript.echo paParseArray(0)
    'WScript.echo CrLf
    'WScript.echo paParseArray(1)
       
    ' ie a valid selection was returned from GetComboInput, so use the return code ( pi_Result) which represents the item
    ' selected to select the item from the paParseArray which is the cbparam parameter minus the exe and the /p: with
    ' the /p: parameters split into the paParseArray ( ie D,L,R,S,V.... )
    pfParseResult = paParseArray(pi_Result - 1)
       
               
    'Do While objWshScriptExec.Status =0
    'WScript.Sleep 100
    'WScript.Echo "this is the status code" & objWshScriptExec.Status
    'Loop

       


         
    End Function


    just code, no beer...although that would probably help..


    Tuesday, March 12, 2013 2:55 AM
  • Hi Sandy,

    Just like what RiffyRiot, it is up to you.

    FYI, I have the same issue but I did not use Get-WMIobject, I just use the netsh script that you have there. Below is my netsh script.

    REM Disabling the NIC card
    REM netsh interface set interface name="Local Area Connection" admin=disabled
    netsh interface set interface name="Local Area Connection" admin=disabled

    REM Enabling the Wireless card
    REM netsh interface set interface name="Wireless Network Connection" admin=enabled
    netsh interface set interface name="Wireless Network Connection" admin=enabled


    Thanks and best regards, Kim Seng This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

    Tuesday, March 12, 2013 3:48 AM
  • how about this script from the scripting guys..below ( you should be able to get source from their site, or copy below )

    <#
       .Synopsis
        Enables, Disables, Queries network adapter from local or remote computer
       .Description
        This script Enables, Disables, Queries network adapter 
        from local or remote computer. To enable or disable requires admin rights. 
        This script relies upon the default nameing of the network connections, ex:
        "Local Area Connection" or "Wireless Network Connection" if you have renamed
        your connection you will need to specify name of connection by using the 
        custom parameter. 
         Parameters
          -computer name of the computer. Localhost by default
          -wireless manage the wireless adapter <enable, disable, query>
          -wired  manage the wired adapter <enable, disable, query>
          -custom custom name of either wired or wireless adapter. Use to specify
           a custom name that appears in network connections in control panel. You cannot
           use a custom name when working with both network adapters at the same time. This
           is because custom is a shared parameter between the two. 
       .Example
        EnableDisableNetworkAdapters.ps1 -wired query
        Reports basic information about the wired network adapter. The wired network adapter
        is named something like "Local Area Connection."
       .Example
        EnableDisableNetworkAdapters.ps1 -wired query -wireless query
        Reports basic information about both the wired and wireless network. The wireless 
        adapter is named something like "Wireless Network Connection" and the wired adapter
        is named something like "Local Area Connection." When querying both wired and wireless
        at the same time, you cannot use a custom name! 
       .Example
        EnableDisableNetworkAdapters.ps1 -wired query -custom "My custom nic"
        Reports basic information about a wired network card named "my custom nic"
       .Example
        EnableDisableNetworkAdapters.ps1 -wired disable
        Disables the wired network adapter (Requires Admin rights)
       .Example
        EnableDisableNetworkAdapters.ps1 -wired disable -wireless enable
        Disables the wired network adapter and enables the wireless network adapter 
        (Requires Admin rights)
       .Inputs
        [string]
       .OutPuts
        [string]
       .Notes
        NAME:  Windows 7 Resource Kit
        AUTHOR: Ed Wilson 
        LASTEDIT: 5/20/2009
        KEYWORDS:
       .Link
         Http://www.ScriptingGuys.com
    #Requires -Version 2.0
    #>
    Param(
        [Parameter(Position=0)]
        [string]
        $computer = $env:computername,
        [string]
        $wireless,
        [string]
        $wired,
        [string]
        $custom
    ) #end param

    # Begin Functions

    function New-Underline
    {
    <#
    .Synopsis
     Creates an underline the length of the input string
    .Example
     New-Underline -strIN "Hello world"
    .Example
     New-Underline -strIn "Morgen welt" -char "-" -sColor "blue" -uColor "yellow"
    .Example
     "this is a string" | New-Underline
    .Notes
     NAME:
     AUTHOR: Ed Wilson
     LASTEDIT: 5/20/2009
     KEYWORDS:
    .Link
     Http://www.ScriptingGuys.com
    #>
    [CmdletBinding()]
    param(
          [Parameter(Mandatory = $true,Position = 0,valueFromPipeline=$true)]
          [string]
          $strIN,
          [string]
          $char = "=",
          [string]
          $sColor = "Green",
          [string]
          $uColor = "darkGreen",
          [switch]
          $pipe
     ) #end param
     $strLine= $char * $strIn.length
     if(-not $pipe)
      {
       Write-Host -ForegroundColor $sColor $strIN
       Write-Host -ForegroundColor $uColor $strLine
      }
      Else
      {
      $strIn
      $strLine
      }
    } #end New-Underline function

    Function GetWireless($wireless,$custom)
    {
     if($custom)
       { $filter = "NetConnectionID LIKE '%$custom%'" }
     Else
       { $filter = "NetConnectionID LIKE '%Wireless%'" }
     NetworkAdapterFactory($wireless)
    }#end GetWireless

    Function GetWired($wired,$custom)
    {
     if($custom)
       { $filter = "NetConnectionID LIKE '%$custom%'" }
     Else
       {
         $filter = "NetConnectionID LIKE '%Local Area%'"
       }
     NetworkAdapterFactory($wired)
    } #end GetWired

    Function NetworkAdapterFactory($adapter)
    {
     $wmi = Get-WmiObject -Class Win32_NetworkAdapter `
     -filter $filter -computername $computer
     switch ($adapter)
     {
      "query" { $wmi | HasWmiValue ; exit}
      "enable" { 
                If(-not (Test-IsAdministrator)) 
                  { New-Underline "Admin rights are required for this script" ; exit }
                $rtn = $wmi.enable() 
                Get-ReturnCode -rtn $rtn -action $adapter
                Exit
               }
      "disable" { 
                 If(-not (Test-IsAdministrator)) 
                   { New-Underline "Admin rights are required for this script" ; exit }
                 $rtn = $wmi.disable() 
                 Get-ReturnCode -rtn $rtn -action $adapter
                 Exit
                }
      DEFAULT { 
                Write-Host -foregroundcolor red "unrecognized parameter." 
                Get-Help $MyInvocation.InvocationName
                Exit 
              }
     } #end switch
    } #end NetWorkAdapterFactory

    Function Get-ReturnCode($rtn,$action)
    {
     if($rtn.returnvalue -eq 0) { "no errors with $action operation" }
     Else { "Error $($rtn.returnvalue) occurred with $action operation" }
    } #end function get-returncode

    Filter HasWmiValue
    {
      ""
       $_.psobject.properties |
       foreach-object `
        {
         If(
            $_.value -AND $_.name -notmatch "__" -AND $_.name -notmatch "Scope" `
             -AND $_.name -notmatch "Path" -AND $_.name -notmatch "Options" `
             -AND $_.name -notmatch "Properties" -AND $_.name -notmatch "Qualifiers"
           )
          {
            @{ $($_.name) = $($_.value) }
          } #end if
        } #end foreach property
    } #end filter HasWmiValue 

    function Test-IsAdministrator
    {
        <#
        .Synopsis
            Tests if the user is an administrator
        .Description
            Returns true if a user is an administrator, false if the user is not an administrator        
        .Example
            Test-IsAdministrator
        #>   
        param() 
        $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
        (New-Object Security.Principal.WindowsPrincipal $currentUser).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
    } #end function Test-IsAdministrator

    # *** Entry Point to script ***

    New-Underline "Connecting to $computer"

    if($wireless) { GetWireless -wireless $wireless -custom $custom}
    if($wired) { GetWired -wired $wired -custom $custom }
    if(!$wired -or !$wireless) { Get-Help $MyInvocation.InvocationName}

    just code, no beer...although that would probably help..

    Tuesday, March 12, 2013 4:05 AM
  • With fullest respect to the IMMENSE amount of code written to satisfy this need why not run the following at a command prompt?:

    wmic path win32_networkadapter where NetConnectionID="Wireless Network Connection" call enable

    or

    wmic path win32_networkadapter where NetConnectionID="Wireless Network Connection" call disable

    Roses are #FF0000, Violets are #0000FF, All my base are belong to you!

    Thursday, February 13, 2014 2:15 PM