Quick tip: finding a text string in PowerShell output
Posted: (EET/GMT+2)
Assume you are working with a PowerShell prompt (say, an Exchange Management Shell), and you are not sure which commands are available. The PowerShell command "get-command" (or in case of Exchange, "get-excommand") gives you this list, but if you only know parts of the proper command name, then you might try to use a DOS classic, the "find" command. For instance, if you were to search for commands containing the word "Debug", you might try the following command:
get-command | find "Debug"
Unluckily though, PowerShell will simply response the following:
FIND: Parameter format not correct
The error will not go away even if you remove the quotation marks.
What could you try, then? One way to solve the problem is to change the command slightly: instead of "find", try "findstr" (for "find string"). This gives you the expected results:
PS C:\> get-command | findstr Debug Cmdlet Complete-Transaction Complete-Transaction [-Verbose] [-Debug] [-Error... Cmdlet Debug-Process Debug-Process [-Name][-Verbose] [-De... Cmdlet Enable-PSRemoting Enable-PSRemoting [-Force] [-Verbose] [-Debug] [... Cmdlet Exit-PSSession Exit-PSSession [-Verbose] [-Debug] [-ErrorAction... Cmdlet Get-Culture Get-Culture [-Verbose] [-Debug] [-ErrorAction ] [-Verbose] [-Debug] [-... Cmdlet Get-PSCallStack Get-PSCallStack [-Verbose] [-Debug] [-ErrorActio... Cmdlet Get-Transaction Get-Transaction [-Verbose] [-Debug] [-ErrorActio... Cmdlet Get-UICulture Get-UICulture [-Verbose] [-Debug] [-ErrorAction ... Cmdlet Get-WSManCredSSP Get-WSManCredSSP [-Verbose] [-Debug] [-ErrorActi... Function prompt $(if (test-path variable:/PSDebugContext) { '[DB... Cmdlet Set-PSDebug Set-PSDebug [-Trace ] [-Step] [-Strict] [... Cmdlet Stop-Transcript Stop-Transcript [-Verbose] [-Debug] [-ErrorActio... Cmdlet Undo-Transaction Undo-Transaction [-Verbose] [-Debug] [-ErrorActi... Cmdlet Write-Debug Write-Debug [-Message] [-Verbose] [-Deb...
With the "findstr" command, you can solve the problem of finding a string from the PowerShell output, which otherwise is object-based. But sometimes, a simple string search is what you are after.
If you instead prefer a more PowerShell-like style, then you could use something like this:
get-command | where {$_.definition -like "*Debug*"}
As you can see, the "findstr" command is more convenient.