Exercise - Locate commands
Note
In this unit, you use Azure Cloud Shell as a terminal. You can access Cloud Shell through the Azure portal or the Cloud Shell sign-in. You don't have to install anything on your PC or laptop to use it.
Here, you run commands that help you learn more about PowerShell. PowerShell isn't something you learn overnight; it's learned command by command. You can speed up your learning by effectively using the core cmdlets.
Note
This exercise is optional. If you want to complete this exercise, you'll need to create an Azure subscription before you begin. If you don't have an Azure account or you don't want to create one at this time, you can read through the instructions so you understand the information that's being presented.
Locate a command
Locate commands by running the Get-Command cmdlet. This cmdlet helps you search all of the cmdlets installed on your system. Use flags to narrow down your search results to just the cmdlets that fit your scenario.
In this scenario, you're looking for a cmdlet that can help you work with files.
Run the command
Get-Commandwith the flag-Noun. SpecifyFile*to find anything related to files.Get-Command -Noun File*The response shows something similar to the following text:
CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-FileHash 7.0.0.0 Microsoft.PowerShell.Utility Cmdlet Out-File 7.0.0.0 Microsoft.PowerShell.Utility Cmdlet Unblock-File 7.0.0.0 Microsoft.PowerShell.UtilityThe cmdlets
Get-FileHash,Out-File, andUnblock-Fileall match your query. Now, you have a manageable response. To further filter the response, add the-Verbparameter to your query.Run
Get-Command. Specify the flags-Verband-Noun.Get-Command -Verb Get -Noun File*The result is similar to the following output:
CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-FileHash 7.0.0.0 Microsoft.PowerShell.UtilityThis time, only one record matches your search, because you specified both the
-Nounparameter and the-Verbparameter.
Because the domain you work in is file management, you specified File as the noun. If you know what you want to do within that domain, you can specify -Verb parameters. By using one or possibly two parameters, you can quickly find the cmdlet you need.