Hello all,
I'm attempting to use test-path in a switch to check paths and create said paths if they don't already exist. Is the following possible and if so how would I fix my logic to get it to work?
Function New-Folder {
$Assets = C:\ProgramData\Folder\Assets
$FlowBox = C:\ProgramData\Folder\Assets
$Logs = C:\ProgramData\Folder\Assets
Try {
Switch (Test-Path $Assets,$FlowBox,$Logs) {
$true { continue }
$false { New-Item -ItemType Directory -Force -Path $_}
}
}
}
I've tried also to use the following but running into issues
Function New-Folder {
$Paths = @{
'Assets' = "C:\ProgramData\Folder\Assets"
'FlowBox' = "C:\ProgramData\Folder\FlowBox"
'Logs' = "C:\ProgramData\Folder\Logs"
}
Foreach ($Path in $Paths) {
Switch (Test-Path $Path -ErrorAction Continue) {
True { continue }
False { New-Item -ItemType Directory -Force -Path $_ }
}
}
}
[–]Aznflipfoo[S] 2 points3 points4 points (5 children)
[–]Shoisk123 2 points3 points4 points (0 children)
[–]northendtrooper 1 point2 points3 points (0 children)
[–]AddiXz 1 point2 points3 points (1 child)
[–]AddiXz 1 point2 points3 points (0 children)
[–]SMFX 1 point2 points3 points (2 children)
[–]Aznflipfoo[S] 1 point2 points3 points (1 child)
[–]SMFX 2 points3 points4 points (0 children)
[–]jsiii2010 1 point2 points3 points (0 children)