COS
Expert
Expert

Problems returning variable value

My variable is called $ps-testvm_DRSAutomationLevel

I populate it with the below....

Set-Variable -Name $ps-testvm_DRSAutomationLevel -Value "Yomama"

That appears to run.

When I echo out the value I get this...

PS C:\Windows\system32> $ps-testvm_DRSAutomationLevel

At line:1 char:4

+ $ps-testvm_DRSAutomationLevel

+    ~~~~~~~

Unexpected token '-testvm' in expression or statement.

At line:1 char:11

+ $ps-testvm_DRSAutomationLevel

+           ~~~~~~~~~~~~~~~~~~~

Unexpected token '_DRSAutomationLevel' in expression or statement.

    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : UnexpectedToken

I tried escaping the - char by doing this....

$ps-`testvm_DRSAutomationLevel

$ps`-testvm_DRSAutomationLevel

$ps`-`testvm_DRSAutomationLevel

But no worky worky.

I need to keep the "-" char because it is part of all the VM names.

Any ideas?

Thanks

Gene Laoyan

0 Kudos
3 Replies
LucD
Leadership
Leadership

You don't use the $ sign on the Name parameter

Set-Variable -Name ps-testvm_DRSAutomationLevel -Value "Yomama"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

And if you want to use a special character in the variable name, you can reference it like this

${ps-testvm_DRSAutomationLevel}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

Was this working for you?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos