So test-path makes most sense to me as well, but the If won't even execute of the path is invalid? How do you work around that?
Thanks for all the help... jlc -----Original Message----- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 1:45 PM To: NT System Admin Issues Subject: Re: Powershell Question I think you can try this: $sfDesktop = [Environment]::GetFolderPath("Desktop") If(!(test-path $sfDesktop)) { write-host "Something's wrong" } Else { write-host "It worked" } On Tue, Sep 7, 2010 at 3:50 PM, Joseph L. Casale <jcas...@activenetwerx.com> wrote: > Hey Rubens, > I am not too concerned with how I get the value, but more on how to trap if > it doesn't enumerate correctly. > Once I start looping through all the special folders of interest, I don't > want to send something wrong into the routine that follows. > > Thanks! > jlc > > -----Original Message----- > From: Rubens Almeida [mailto:rubensalme...@gmail.com] > Sent: Tuesday, September 07, 2010 12:46 PM > To: NT System Admin Issues > Subject: Re: Powershell Question > > I'd try something like this: > > $sfDesktop = $env:USERPROFILE + "\desktop" > > On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale > <jcas...@activenetwerx.com> wrote: >> Hey Guys, >> >> What's the most simple and elegant way to trap for the following variable >> assignment: >> >> Eg. $sfDesktop = [Environment]::GetFolderPath("Desktop") >> >> >> >> Should I assign it like this, and test for a proper value when using (skip >> otherwise while I cycle through all the ones I need to)? If so, how do you >> test the value for it having been properly assigned? >> >> >> >> Sorry, ps noob here. >> >> 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 listmana...@lyris.sunbeltsoftware.com >> 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 listmana...@lyris.sunbeltsoftware.com > 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 listmana...@lyris.sunbeltsoftware.com > 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 listmana...@lyris.sunbeltsoftware.com 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 listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin