Last active
September 26, 2022 12:02
-
-
Save techthoughts2/5fd2452bdd32ad745ed0 to your computer and use it in GitHub Desktop.
Evaluates if a directory is present. if not found, the specified directory will be created.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (-not(Test-Path -Path $TargetDir -ErrorAction Stop )) { | |
Write-Verbose -Message ('Output directory {0} not found. Creating...' -f $TargetDir) | |
$newItemSplat = @{ | |
ItemType = 'Directory' | |
Path = $TargetDir | |
ErrorAction = 'Stop' | |
} | |
try { | |
New-Item @newItemSplat | |
Write-Verbose -Message 'Created.' | |
} | |
catch { | |
Write-Warning -Message 'An error was encountered creating the output directory:' | |
Write-Error $_ | |
return | |
} | |
} | |
else { | |
Write-Verbose -Message 'Output directory verified.' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment