I wanted my filename to be:
Richard_Brown.txt
And my powershell read something like:
$File = "C:\$FirstName_$LastName"
Interestingly, when run in my script the output of $File would be
C:\Brown.txt
I was suspicious of the underscore and sure enough this was the causing the issue. I stumbled upon this thread on Stackoverflow which explains the issue as the underscore is a valid character in identifiers so its looking for a variable named $FirstName_.
There are 2 workarounds for this:
1) $File = "C:\$FirstName`_$LastName"
2) $File = "C:\${FirstName}_$LastName"
No comments:
Post a Comment