2007-09-13

Enabled / Disable Network Adapter with Powershell

All i wanted to do was enable a network connection using powershell.

But unfortunately the easy way only works on Vista, and i needed it in Windows Server 2003. http://blogs.msdn.com/daiken/archive/2007/02/09/enable-disable-network-connection.aspx

I had to go digging around for how you used to have to enable the connection with wsf. http://mcpmag.com/columns/article.asp?EditorialsID=619

And then converted it into something i could use in powershell.

$shell = New-Object -comObject Shell.Application
((($shell.NameSpace(3).Items() | where {$_.Name -eq "Network Connections"}).GetFolder.Items() | where {$_.Name -eq "Local Area Connection"}).Verbs() | where {$_.Name -eq "En&able"}).DoIt()

And to disable.

$shell = New-Object -comObject Shell.Application
((($shell.NameSpace(3).Items() | where {$_.Name -eq "Network Connections"}).GetFolder.Items() | where {$_.Name -eq "Local Area Connection"}).Verbs() | where {$_.Name -eq "Disa&ble"}).DoIt()

At must have had at least 30 tabs open in my browser by the time i got this to work.