Comments on: PowerShell create folder if not exists https://www.spguides.com/create-folder-if-not-exists-using-powershell/ Learn SharePoint, Office 365, Nintex, PowerApps, PowerBI etc, SharePoint training and video courses Sun, 10 Dec 2023 04:15:32 +0000 hourly 1 https://wordpress.org/?v=6.6.2 By: J https://www.spguides.com/create-folder-if-not-exists-using-powershell/#comments/699 Wed, 01 Jun 2022 23:25:39 +0000 https://www.sharepointsky.com/?p=798#comment-699 Thank you for this.
I would suggest one change by adding an additional variable for the -Path so the script can be quickly used anywhere with just changing the variables at the top.

$folderName = (Get-Date).tostring(“dd-MM-yyyy”)
$root=”E:Desktop”
$path=$Root+$folderName
if (!(Test-Path $Path))
{
New-Item -itemType Directory -Path $root -Name $FolderName
}
else
{
write-host “Folder already exists”
}

]]>