PowerShell Commands Structure
As in every command line interface you have to know the commands and the difficult part is to remember them. In this tutorial we will see a few things regarding PowerShell commands structure that will help you out to have a better understanding and may help you to memorize commands easier. PowerShell uses cmdlets, which follow one simple rule Verb-Noun -Parameter.
Every single command will start with the Verb which indicates the action that we want to perform. The most common verbs, in my opinion, are Get and Set. Each Verb is easily recognizable and memorable to help you remember or find out the cmdlet that you need to use. You are able to get the full list of PowerShell’s approved verbs using the following command:
PS C:\Users\Stephanos> Get-Verb Verb Group ---- ----- Add Common Clear Common Close Common Copy Common Enter Common Exit Common Find Common Format Common Get Common Hide Common Join Common Lock Common Move Common New Common Open Common Optimize Common Pop Common Push Common Redo Common Remove Common Rename Common Reset Common Resize Common Search Common Select Common Set Common Show Common Skip Common Split Common Step Common Switch Common Undo Common Unlock Common Watch Common Backup Data Checkpoint Data Compare Data Compress Data Convert Data ConvertFrom Data ConvertTo Data Dismount Data Edit Data Expand Data Export Data Group Data Import Data Initialize Data Limit Data Merge Data Mount Data Out Data Publish Data Restore Data Save Data Sync Data Unpublish Data Update Data Approve Lifecycle Assert Lifecycle Complete Lifecycle Confirm Lifecycle Deny Lifecycle Disable Lifecycle Enable Lifecycle Install Lifecycle Invoke Lifecycle Register Lifecycle Request Lifecycle Restart Lifecycle Resume Lifecycle Start Lifecycle Stop Lifecycle Submit Lifecycle Suspend Lifecycle Uninstall Lifecycle Unregister Lifecycle Wait Lifecycle Debug Diagnostic Measure Diagnostic Ping Diagnostic Repair Diagnostic Resolve Diagnostic Test Diagnostic Trace Diagnostic Connect Communications Disconnect Communications Read Communications Receive Communications Send Communications Write Communications Block Security Grant Security Protect Security Revoke Security Unblock Security Unprotect Security Use Other
As you can see above,
Get-Verb gives you a list of all verbs and the group that it belongs to.
The verb then is followed by a dash (-) and a Noun. The noun is the object or object type that you want to perform the action. Lets take two different objects and find out any cmdlets that they are related to these two. We will look at the Process and Service cmdlets.
PS C:\Users\Stephanos> Get-Command -Noun Service CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-Service 188.8.131.52 Microsoft.PowerShell.Management Cmdlet New-Service 184.108.40.206 Microsoft.PowerShell.Management Cmdlet Restart-Service 220.127.116.11 Microsoft.PowerShell.Management Cmdlet Resume-Service 18.104.22.168 Microsoft.PowerShell.Management Cmdlet Set-Service 22.214.171.124 Microsoft.PowerShell.Management Cmdlet Start-Service 126.96.36.199 Microsoft.PowerShell.Management Cmdlet Stop-Service 188.8.131.52 Microsoft.PowerShell.Management Cmdlet Suspend-Service 184.108.40.206 Microsoft.PowerShell.Management
PS C:\Users\Stephanos> Get-Command -Noun Process CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Debug-Process 220.127.116.11 Microsoft.PowerShell.Management Cmdlet Get-Process 18.104.22.168 Microsoft.PowerShell.Management Cmdlet Start-Process 22.214.171.124 Microsoft.PowerShell.Management Cmdlet Stop-Process 126.96.36.199 Microsoft.PowerShell.Management Cmdlet Wait-Process 188.8.131.52 Microsoft.PowerShell.Management
As you can see above all commands related they follow the same pattern of Verb-Noun.
Some nouns have prefixes based on the module and the object that you are working on. Below is the list of those prefixes:
- PS – Powershell
- AD – Active Directory
- DHCP – DHCP Server
- DNS – DNS Server and Client
- NET – Networking
- GP – Group Policy
- VM – Hyper-V
- SQL – SQL Server
- Web – Web Administration
- IIS – IIS Administration
- SP – SharePoint
- SPO – SharePoint Online
- Azure – Azure
- MSMQ – Microsoft Messaging Queue
After the cmdlet name, parameters maybe supplied. It is not always nessesary to state the name of The parameter, and while some parameters are mandatory, others van be ommited entirely. The are common parameters for all cmdlets and specific parameters for each of the cmdlets. The common parameters are the below:
I hope the tutorial about PowerShell commands structure is helpful.
Please let me know your comments and thoughts. You feedback is appreciated.