| by Arround The Web | No comments

Get-ChildItem: Listing Files, Registry and Certificates

The cmdlet “Get-ChildItem” retrieves the item and child items from specified locations. If in case the item is a container then it will get the items from it called the child items. Moreover, in order to get the values from subdirectories the “-Recurse” parameter is used. The “Get-ChildItem” cmdlet does not display the empty folders or directories in the output.

This post has elaborated on the “Get-ChildItem” cmdlet in PowerShell.

Get-ChildItem: Listing Files, Registry, and Certificates

The stated cmdlet gets the items and the child items from the provided file path. Examples related to the stated cmdlet are demonstrated below.

Example 1: Get the Items List in a Directory Using the “Get-ChildItem” Cmdlet

This example will get the items located in the specified directory:

Get-ChildItem C:\Docs

Example 2: Get the Names of Items in a Directory

This example will only get the names of the files located in the specified directory:

Get-ChildItem C:\Docs -Name

In the stated above code:

  • First, specify the “Get-ChildItem” cmdlet along with the file path.
  • Lastly, add the “-Name” parameter to get the list of file names:

Example 3: Get the Child Items in the Directory and Sub-Directory

In this illustration, the child items available in the sub-directories will also be retrieved:

Get-ChildItem C:\Docs\*.txt -Recurse -Force

According to the above code:

  • First, specify the “Get-ChildItem” cmdlet, along with the directory path having the “*” wildcard.
  • After that specify the “-Recurse” parameter to get the items from sub-directories and then use the “-Force” parameter:

Example 4: Use the “Get-ChildItem” Cmdlet to Get the Registry Keys

This demonstration will retrieve the registry keys using the given code:

Get-ChildItem -Path HKLM:\HARDWARE

In the above-stated code:

  • First, specify the “Get-ChildItem” cmdlet, along with the “-Path” parameter, and assign the registry key path:

Example 5: Get All the Certificates With Code Signing Authority

In this demonstration, the code-signed certificates will be retrieved using the given code:

Get-ChildItem -Path Cert:\LocalMachine\My

In the stated code above:

  • First, specify the “Get-ChildItem” cmdlet, followed by the “-Path” parameter having the path to the code-signed certificates:

That was all about listing files, registry, and certificates.

Conclusion

The cmdlet “Get-ChildItem” retrieves the items and child items from the provided file path by a user. Moreover, the “-Recurse” parameter is used with the stated cmdlet to retrieve the items from a sub-directory. This post has demonstrated the “Get-ChildItem” cmdlet with several examples.

Share Button

Source: linuxhint.com

Leave a Reply