16 December,2012 by Tom Collins
Question: How can list out all the items in a specified location using Powershell?
Answer: Use the Get-ChildItem cmdlet . This cmdlet takes the DIR command and extends it into a flexible and powerful cmdlet.
This cmdlet will return the items in multiple locations. An item can be a container – in that case it will return all the items in the container – known as child items.
A note on locations. Directories are typical locations , but other locations can be registries .
#An example of listing items in a directory Get-ChildItem -path "C:\laboratory" #An example of listing items in a directory and -include Get-ChildItem -path "C:\laboratory\*.*" -include *.txt #An example of listing items in a directory and -exclude Get-ChildItem -path "C:\laboratory\*.*" -exclude *.txt #An example of listing the items, filtering name and length and using sort-object Get-ChildItem -path "C:\laboratory"| select name,length | sort-object -property length #An example to return the environment variables Get-ChildItem env: #An example of obtaining subkey information Get-ChildItem HKLM:\SOFTWARE\Microsoft\ #An example to list all items with recurse Get-ChildItem -path "C:\laboratory\" –Recurse #Warning!!!!!!!!!!!!! This example DELETES all items at path Get-ChildItem -path "C:\laboratory\removeitem\" -Recurse | remove-item
It is not always possible to use Powerrshell. An alternative to Powershell Get-ChildItem is Display all files in a directory with master.sys.xp_dirtree
Powershell - run script on all sql servers
SQL Server - SQL Server Restart with Powershell
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |