Until recently VBScript was king for admin scripting in the Windows environment. This set up a certain way of doing things in people’s minds. I saw a lot of that in the Scripting Games. One example that comes to mind is testing if a path exists.
In PowerShell we can do
Test-Path -Path c:\test\test1.txt
which on my system will return true (at the moment). If I change it to
Test-Path -Path c:\test\test2.txt
I’ll get false as the answer. The important point to remember is that these are boolean values being returned from the System.Boolean class not text saying “true” or “false”
I saw a lot of this structure
$test = Test-Path -Path c:\test\test2.txt
if ($test -match "false"){New-Item -Path c:\test -Name test2.txt -ItemType File}
Another option I saw was
if ($test -eq $false){New-Item -Path c:\test -Name test2.txt -ItemType File}
A better way, from a PowerShell perspective is to do this
if (!(Test-Path -Path c:\test\test2.txt)){New-Item -Path c:\test -Name test2.txt -ItemType File}
We do the test-path as part of the if test condition and create the file if test-path returns false
Keep it simple and use the power that is delivered when you install PowerShell