Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How to check if $($var) exists?

$
0
0

Hi guys

I hope you can help me!

Let's say I have this:

$XXX = "TTT"

$Department = "XXX - Hello"

$Test = ($Department.Split(" "))[0]

If($($Test) -eq "TTT") {Write-Host "Does it work?"}
The If statement is the problem. I would like for it to replace $($Test) with $XXX and then check if that variable exists. But while $Test returns the string "XXX" it doesn't seem to accept that I want to insert a $ sign in front and check if this variable exists. Is there some way of doing this, that I'm just not seeing? I've tried writing it a bunch of different ways without any luck.



Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images