PowerShell Terminal tips and tricks

It’s been a busy week, preparing for a big customer migration this weekend and scripting for it… I realized that I use some Terminal things that are worth sharing in this small blog 🙂

Search your shell history

While it does work to use your Up and Down arrows to scroll in your PowerShell command-line history, there is a way to search for a specific command by pressing Ctrl+R. For example, I know I did something with MSCommerce, but I’m not sure what the command line was. PSReadline does help, but not with multi-line or Piped Commands. So, I pressed Ctrl+R, the bck-i-search prompt appeared, and I typed MSCommerce. First hit was not what I was looking for, pressed CTRL+R again to go back to another command, and again until I found this:

If I hit Enter, it will execute that multi-line command again. But sometimes you go past the result you wanted; you can then press Ctrl+S to search forward again by one result. Both CTRL+R and CTRL+S can be used as long as they return results. When you’re at the last result, it will show you a failed-bck-i-search or a failed-fwd-i-search prompt depending on the direction 😉

Copy to clipboard

Sometimes I even forget that it’s there, but when storing results, I use a CSV/XLSX file or a TXT file, then edit it and copy/paste it into another program, etc. You can also use the Out-Clipboard Cmdlet to copy the results of something to your clipboard; you only have to do CTRL-V to copy it. For example:

And when I press CTRL-V here:

"Name","SI","Handles","VM","WS","PM","NPM","Path","CommandLine","Parent","Company","CPU","FileVersion","ProductVersion","Description","Product","__NounName","SafeHandle","Handle","BasePriority","ExitCode","HasExited","StartTime","ExitTime","Id","MachineName","MaxWorkingSet","MinWorkingSet","Modules","NonpagedSystemMemorySize64","NonpagedSystemMemorySize","PagedMemorySize64","PagedMemorySize","PagedSystemMemorySize64","PagedSystemMemorySize","PeakPagedMemorySize64","PeakPagedMemorySize","PeakWorkingSet64","PeakWorkingSet","PeakVirtualMemorySize64","PeakVirtualMemorySize","PriorityBoostEnabled","PriorityClass","PrivateMemorySize64","PrivateMemorySize","ProcessorAffinity","SessionId","StartInfo","Threads","HandleCount","VirtualMemorySize64","VirtualMemorySize","EnableRaisingEvents","StandardInput","StandardOutput","StandardError","WorkingSet64","WorkingSet","SynchronizingObject","MainModule","MainWindowHandle","MainWindowTitle","Responding","ProcessName","PrivilegedProcessorTime","TotalProcessorTime","UserProcessorTime","Site","Container"
"OneDrive","1","0","446280499200","64684032","0","0","/Applications/OneDrive.app/Contents/MacOS/OneDrive","",,,"153.243175",,,,,"Process","Microsoft.Win32.SafeHandles.SafeProcessHandle","312","0",,"False","6/19/2026 9:40:59 AM",,"13935",".",,,"System.Diagnostics.ProcessModuleCollection","0","0","0","0","0","0","0","0","0","0","0","0","False","Normal","0","0",,"1",,"System.Diagnostics.ProcessThreadCollection","0","446280499200","-396099584","False",,,,"64684032","64684032",,"System.Diagnostics.ProcessModule (OneDrive)","0","","True","OneDrive","00:00:28.9569291","00:02:33.2431750","00:02:04.2862458",,
"OneDrive","1","0","446279811072","77266944","0","0","/Applications/OneDrive.app/Contents/MacOS/OneDrive","",,,"31.34045",,,,,"Process","Microsoft.Win32.SafeHandles.SafeProcessHandle","820","0",,"False","6/19/2026 9:41:00 AM",,"13939",".",,,"System.Diagnostics.ProcessModuleCollection","0","0","0","0","0","0","0","0","0","0","0","0","False","Normal","0","0",,"1",,"System.Diagnostics.ProcessThreadCollection","0","446279811072","-396787712","False",,,,"77266944","77266944",,"System.Diagnostics.ProcessModule (OneDrive)","0","","True","OneDrive","00:00:10.0060208","00:00:31.3404500","00:00:21.3344291",,
"OneDrive","1","0","446271586304","64323584","0","0","/Applications/OneDrive.app/Contents/MacOS/OneDrive","",,,"147.8885375",,,,,"Process","Microsoft.Win32.SafeHandles.SafeProcessHandle","836","0",,"False","6/19/2026 9:41:01 AM",,"13940",".",,,"System.Diagnostics.ProcessModuleCollection","0","0","0","0","0","0","0","0","0","0","0","0","False","Normal","0","0",,"1",,"System.Diagnostics.ProcessThreadCollection","0","446271586304","-405012480","False",,,,"64323584","64323584",,"System.Diagnostics.ProcessModule (OneDrive)","0","","True","OneDrive","00:00:27.3637416","00:02:27.8885375","00:02:00.5247958",,

Note: Not all output that you pipe to Set-Clipboard will look like you expect:

Results in:

System.Diagnostics.Process (OneDrive)
System.Diagnostics.Process (OneDrive)
System.Diagnostics.Process (OneDrive)

Using ConvertTo-… could be convenient.

Finding CmdLets

Sometimes you just don’t know the name of a Graph Cmdlet to do something with Conditional Access Policies, for example. Using Get-Help *ConditionalAccessPolicy* will show you every Cmdlet matching that. For example:

You can also use Get-Command *conditionalaccesspolicy*

Transcript logging

I do that a lot, certainly in scripts, but using Start-Transcript c:\temp\powershell_log.txt, for example, in your session makes it easier to scroll back/read what happened:

PSReadline

The best module for your Terminal, PSReadline 🙂 I have added that tot my profile with these settings:

Set-PSReadLineKeyHandler -Key Tab -Function Complete
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -PredictionSource History

When typing, it will show you history to select from (But not the ones with multiple lines, see the Chapter above “Search your shell history”. For example:

Wrapping up

And that’s it, some tips and tricks on this very hot day in Zaandam and waiting for my migration tasks to finish 🙂 Have a lovely weekend!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.