in

WindowsWindows Loving ItLoving It

PowerShell Recurse Directory & Registry for Beginners -Recurse

Use -Recurse to do advanced search in Directory and Registry. PowerShell Recurse is most searched feature in Windows. Latest solution for [2020]

PowerShell -recurse

PowerShell recurse is very powerful for searching and more.  It will be generally used with get-childitem.  It is also called iteration or sub-directories recursion.

Jump to:

People also search for:

PowerShell recurse basic example:

get-childitem -recurse

The below example demonstrates the difference.

  • We will run get-childitem first
get-childitem
  • And then run the same command with recurse.
get-childitem -recurse
get-childitem with recurse
get-childitem with recurse

PowerShell search Registry with the help of Recurse:

We will use the command to search the Registry in the following path:

gci “HKLM:\Software\Microsoft\PowerShell” -recurse
registry gci recurse
registry gci recurse

Note that we are not using the complete get-childitem command but we are using only the alias.  The alias for get-childitem is gci.

gci
gci

PowerShell recurse with custom format table:

From the previous example, it is very clear that the output contains the path in the middle.  This is distracting and sometimes not elegant.  We will implement a custom table using a format table flag as shown below.

gci -recurse | %{if($_.extension -match ‘pdf’){$_}} | ft -group {$_.path} Directory, Name -autosize
format table
format table
  • We can see that we are using ft to implement the format table,
  • -group for grouping the output.
  • {$.path} Directory to name the column of the path as a directory.
format table
format table
  • Name to include the Name property.

We will execute the command without the format table and get the following output:

gci -recurse | %{if($_.extension -match ‘pdf’){$_}}
without format table
without format table

Verdict:

In this post, we learned some basics of PowerShell recurse.  We learned the basic example.  The recurse flag can be used for registry also.  Finally, we used the custom table in order to show the output in just two columns.

If you want more such posts, stay tuned to TecKangaroo.

Leave a Reply

Your email address will not be published. Required fields are marked *