Tuesday, April 2, 2013

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




Friday, October 5, 2012

Replacement Commands

Netdom http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/29/use-powershell-to-replace-netdom-commands-to-join-the-domain.aspx

UPDATE - PowerShell 3.0 now includes a last switch for get-content
get-content <file> -last 5
To watch a log file ...
get-content <file> -wait
but not exactly the same functionality. So a better way is to get the command from Microsoft.

Tail is included in the 2003 Resource Kit and works well in Server 2008 environment.
Download tail here:
http://www.microsoft.com/download/en/details.aspx?id=17657

Thursday, June 14, 2012

Tips and Tricks in 3.0

Latest

From Scripting Guy 5 new tips and tricks

http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/20/my-five-favorite-powershell-3-0-tips-and-tricks.aspx

Create PowerShell profiles

http://msdn.microsoft.com/en-us/library/windows/desktop/bb613488(v=vs.85).aspx

help *  (man for linux)

New window popup
help get-service -showwindow  (v2 help get-process -online )

Auto build you commands
show-command get-wmiobject

Help can get updates
update-help (save-help)

Find the verbs
Get-verb

Find the verbs and count
Measure-object

If you have a conflict
microsoft.powershell.management\get-process

One Line is Magic
get-process | kill -whatif
get-process | kill -confirm

get-process [a-r]*[g-w] | kill -whatif

does it work well in a pipeline?
get-help get-service -full