AskME4Tech

We Do the best to understand Technology

You are here:

List Folders and Subfolders with PowerShell

Welcome in the new Category of Askme4Tech. Here we try to automate IT Tasks with Powershell. PowerShell is an automation platform and scripting language for Windows and Windows Server that allows you to simplify the management of your systems. You don't need to install because it's installed bt default in Windows and Windows Server.

My first article will be something very simple but very diffcult to export at once. How can export all the subfolders names of a folder. It sounds very simple but it's not. So with Powershell you can do it in a minute.

 You can use the Get-ChildItem to get subfolders of a folder.

  • Open the Powershell
  • Go in the folder that you want to export all the subfolder with cd or cd ..
  • Type

  gci -Directory | select parent, name | sort parent

The command will bring the 1st level of subfolders of the folder that you are.

<<gci is an alias of Get-ChildItem >>

 

  • Now type 

gci -Recurse -Directory | select parent, name | sort parent

and check the results

Bring all the subfolders of the folder that you are.

Now if you want these results to export in a csv file type

gci -Recurse -Directory | select parent, name | sort parent | Export-Csv -Path c:\powershelltest\folders.csv 

Of course you can change the path of the csv file after -Path.

Open the folder that you export the csv file to find the file.

  

Very easy , quck without complexity.

Bye for now and i will come back with new commands to automate IT Tasks.

 

 

Similar Posts

How can Change Path of Folder with Logs in MDT 2013

MDT Monitoring is very usefull feature for IT Pro that deploy or Capture Windows Image very often

Powershell Tool to Export Reports from Active Directory

As i mention lot of times in the past Powershell is an amazing tool that can do lot of things.

Keep in Touch with Askme4Tech

Twitter icon
Facebook icon
Google+ icon