I have am using a script, I didn't write it, but its been handed to me to use regularly, and within the script there is a simply function that is failing, that is, a path test and creation if the path doesn't exist.
This is the code that is NOT working:
#Create working directory
$0 = Test-Path "c:\working" if (! $0) { mkdir "C:\working" -ErrorAction:SilentlyContinue }
Ok, although i've worked with scripting here and there, I'm not a guru and often times its the smallest things that leave me stumpted.
IF someone with some wisdom could reply to help me understand 1) what to change to fix this so it works, 2) what the 0$ refers to at the start of this line of code because I have not used it before and am wondering about it
Thanks in advace for assistance.
There appears to be a CR-LF missing, the script should look like this
#Create working directory
$0 = Test-Path "c:\working"
if (! $0) { mkdir "C:\working" -ErrorAction:SilentlyContinue }
The Test-Path cmdlet returns a Boolean ($true or $false) is the directory exists.
The result is stored is stored in variable $O
The If condition does a NOT of the value in $O, so if the directory didn't exist, $o would contain $false, and a NOT $false becomes a $true.
And then the directory is created.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There appears to be a CR-LF missing, the script should look like this
#Create working directory
$0 = Test-Path "c:\working"
if (! $0) { mkdir "C:\working" -ErrorAction:SilentlyContinue }
The Test-Path cmdlet returns a Boolean ($true or $false) is the directory exists.
The result is stored is stored in variable $O
The If condition does a NOT of the value in $O, so if the directory didn't exist, $o would contain $false, and a NOT $false becomes a $true.
And then the directory is created.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for your rapid reply to this, my apologies for not logging in earlier to say thanks!