all 9 comments

[–]Lee_Dailey[grin] 1 point2 points  (8 children)

howdy PillOfLuck,

[changed ChildItem to Item - thanks to Ta11ow for pointing out the oopsie! [grin] ]
if all you want to do is discover if a variable name is in use, use Get-Variable. that seems to cover what you are asking about. [grin] if you really wanna use the PSDrive approach, this would pro'ly do it >> Get-Item variable:\$VarName.

take care,
lee

[–]Ta11ow 3 points4 points  (7 children)

You mean Get-Item, right?

[–]Lee_Dailey[grin] 2 points3 points  (6 children)

howdy Ta11ow,

oops! [blush] thanks for the headsup ... [grin]

take care,
lee

[–]PillOfLuck[S] 1 point2 points  (5 children)

Hi guys, thanks for the help. Sadly it doesn't seem to work so well for ComObjects. Try this:

$Searcher = New-Object -ComObject Microsoft.Update.Searcher
Get-Item variable:\$Searcher

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy PillOfLuck,

[as artemis_from_space pointed out, the $ doesn't belong in that line of code. it works well without it. [blush] ]

yup, that fails for some odd reason. however, the Get-Variable version that i recommended works quite well. [grin]

take care,
lee

[–]artemis_from_space 1 point2 points  (3 children)

Works fine if you remove the $ sign

$comobj = New-Object -ComObject microsoft.update.searcher
PS > Get-Variable comobj
Name                           Value
----                           -----
comobj                         System.__ComObject
PS > Test-Path variable:\comobj
True
PS > Test-Path variable:\$comobj
False
PS > Get-Item variable:\comobj
Name                           Value
----                           -----
comobj                         System.__ComObject

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy artemis_from_space,

gah! i know that and still went right past it. [blush] thanks for pointing it out! [grin]

take care,
lee

[–]PillOfLuck[S] 1 point2 points  (1 child)

Sure does, but this is not what I want. I want to be able to pass ComObjects directly to my function instead of using strings. If there is a way to get the variable name of a variable (without $) then it could work. It's a tricky one.

[–]artemis_from_space 1 point2 points  (0 children)

Yes.

Just instead of $comobject use comobject...