Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active September 26, 2022 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/5fd2452bdd32ad745ed0 to your computer and use it in GitHub Desktop.
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.
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