PowerShell Daily Dose: Get-Command


Get-Command helps you find/search for cmdlets. Simply typing in ‘Get-Command’ will give you a list of all available commands, which probably is not very useful. But if I want to, say, find all commands that contain ‘file’ in them, I can do this:

Get-Command -Name *file*

and the output will be something like this:

CommandType  Name                             ModuleName
-----------  ----                             ----------
Cmdlet       Add-BitsFile BitsTransfer
Cmdlet       Get-AppLockerFileInformation     AppLocker
Cmdlet       Get-WebConfigFile                WebAdministration
Cmdlet       Get-WebFilePath                  WebAdministration
Cmdlet       New-PSSessionConfigurationFile   Microsoft.PowerShell.Core
Cmdlet       Out-File                         Microsoft.PowerShell.Utility
Cmdlet       Test-PSSessionConfigurationFile  Microsoft.PowerShell.Core
Cmdlet       Unblock-File                     Microsoft.PowerShell.Utility
Application  DataProfileViewer.exe
Application  forfiles.exe
Application  openfiles.exe
Application  PROFILER.EXE

So we have a lot of commands from different modules. To just get cmdlets that contain ‘file’ from the module say ‘Microsoft.PowerShell.Core’, I can do this:

Get-Command -Module Microsoft.PowerShell.Core -Name *file*

And the output will be something like this:

CommandType  Name                            ModuleName
-----------  ----                            ----------
Cmdlet       New-PSSessionConfigurationFile  Microsoft.PowerShell.Core
Cmdlet       Test-PSSessionConfigurationFile Microsoft.PowerShell.Core
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s