Friday, January 4, 2013

Network Locations using PowerShell


So you can’t manage your network locations from PowerShell by default.  Here is a great dll you can add to expose network locations.
Download and extract the dll into your scripts directory from http://archive.msdn.microsoft.com/NLM  Look in \NLMCSharp.zip\NLMCSharp\obj\Debug


Add-Type –Path .\Interop.NETWORKLIST.dll
$nlm = new-object NETWORKLIST.NetworkListManagerClass
$nlm.GetNetworks("NLM_ENUM_NETWORK_ALL") | select @{n="Name";e={$_.GetName()}},@{n="Category";e={$_.GetCategory()}},IsConnected,IsConnectedToInternet

Reference from a great article from those scripting guys below
http://blogs.technet.com/b/heyscriptingguy/archive/2012/06/10/weekend-scripter-use-powershell-to-manage-windows-network-locations.aspx