Always check first
As a System Administrator I’m always looking for automation and easier or faster ways to do my job properly.
When I’m creating scripts which involve of creating or checking if something exists it prevents errors in output and is a nicer and cleaner way to go about doing scripts, why would you want to create something exists anyways?
Writing scripts or snippets I use the command Test-Path combined with an if statement and it depends what I want to do if I’m going to use the negative “NOT”, let me give you an example.
$path = "C:\temp" if(Test-Path -Path $path) { Write-Host "The path `"$path`" already exists" } else { New-Item -Path $path -ItemType Directory }(more…)