PowerShell – Create Directory

Note: This is a recovered post from my old blog. See how we recovered these posts using the Wayback Machine and AI tooling.

Create a directory after checking if it already exists. A common pattern in PowerShell automation - check first to avoid errors when the directory might already be there.

$dir = "C:\test" #Directory you want to make or check if exist
If(!(test-path $dir))
{
New-Item -ItemType Directory -Force -Path $dir
}