How to Create Directory (Folder) using PowerShell Execution


Sathish Nadarajan
SharePoint MVP
Published On :   11 May 2016
Visit Count
Today :  4    Total :   3024
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

Migratiin Tools for SharePoint