How to Create Directory (Folder) using PowerShell Execution

Sathish Nadarajan
 
Solution Architect
May 11, 2016
 
Rate this article
 
Views
4923

Related to the previous article, as part of creating the files, I need to create a separate folder as well, so that the generated reports will be stored in the folder. To make sure that the folder is already available, and if not, create a new folder, a simple two liner script will be sufficient. Though it is too small, wanted to share with the community.

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 ################# Set the Current Path as Execution Path ####################
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase
 ############# set the Error Preference ################
 $ErrorActionPreference = "Stop"
 # Create Log File Folder
 if(!(TEST-PATH ".Logs-$LogTime")) 
 {
    NEW-ITEM ".Logs-$LogTime" -type Directory
 }
 

Happy Coding,

Sathish Nadarajan.

Category : PowerShell

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment