I have a Powershell script and no matter what I try it completely ignores any quotation marks in the script. The error occurs when I run the script from my VB.NET code yet, I have been running scripts successfully through VB.NET for a while now.
For example, my script starts with finding out the server name…
This works:
$name = gc env:computername
This does not:
$name = "SERVERNAME"
The error given is something along the lines of $name = SERVERNAME is not recognized as a cmdlet…. and so on.
This is causing several lines in my script to fail and the error message always displays the command WITHOUT the quotation marks.
When assigning string values you have to quote them (single or double quotes).
$name = ‘SERVERNAME’
or
$name = “SERVERNAME”
or assign it directly to a variable (doesn’t require quotes):
$name = $env:COMPUTERNAME