Learning how to use PowerShell or PoSH commands

Thanks to Mark Minasi, I see some fantastic new PowerShell or PoSH commands. Yes, I am going to reprint portions of it word for word.


1. Some of PowerShell's built-in nouns are ACL, Date, Event, EventLog, ComputerRestorePoint, AuthenticodeSignature, Service and Random. Notice that they're always singular -- it's never get-processes, it's get-process. One way is to use a command called get-command to, well, get information about all of the currently-loaded PowerShell cmdlets. You can even tell get-command to extract just the nouns, sort them and show them:

get-command -type cmdlet|sort noun|select noun|get-unique -asstring

add in the AD module if you are looking at Active Directory


Import-Module ActiveDirectory

2. Using the command "get-command *-noun," or

Get-Command *-aduser

3. Get help on the command, usage, description, etc...

Get-Help cmdlet -(full/examples/detailed)
Help Get-VMhost -examples

4. Use the Command

get-aduser -filter * -properties displayname

the output looks like this:

DisplayName : Thomas Jefferson
DistinguishedName : CN=TJefferson,CN=Users,DC=apple-orchard,DC=net
Enabled : True
GivenName : Thomas
Name : TJefferson
ObjectClass : user
ObjectGUID : e0f5f77e-1d65-4c59-83f4-0164eba1eebb
SamAccountName : TJ
SID : S-1-5-21-2302930610-509929598-2600203374-1606
Surname : Jefferson
UserPrincipalName : thomas@minasi.com

5. Filter the results

Using commands like select, where-object can reduce the insanely huge results that some of these commands can produce. A great example of this is in one of my other posts is using the get-service cmdlet and filtering the by the displayname.


get-service | where {$_.DisplayName -match "VMware"}

This is a great primer to get individuals going and is good for the beginner to create one liners.