Write a function.

You can also do this with a filter, but almost no one uses filters. And it 
wouldn't reduce your line count any more than a function would.

-----Original Message-----
From: Joseph L. Casale [mailto:[email protected]] 
Sent: Tuesday, April 03, 2012 5:27 PM
To: NT System Admin Issues
Subject: Powershell question

Hey guys,

What is the most elegant way to -xor test two paths and keep the one that 
exists?
I have a bunch of cases where I check for the existence of two reg keys (both 
can not co-exist) and then set a variable based on either one.

If ((Test-Path "hklm:\..." ) -xor (Test-Path "hklm:\..." )) {
     $var = value1 or value2
} Else {
     <must exit the script>
}

is the logic I need, but then I need additional code to set a single variable 
to value1 or value2.
Not a big deal once, but I have several and I was just hoping for a slick way 
to accomplish setting $var to either value based on which side tests true w/o 
another if block.

Thanks,
jlc
~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ 
<http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin


~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to