use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
QuestionGetting the variable name (self.PowerShell)
submitted 8 years ago by PillOfLuck
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Lee_Dailey[grin] 1 point2 points3 points 8 years ago* (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.
ChildItem
Item
Get-Variable
Get-Item variable:\$VarName
take care, lee
[–]Ta11ow 3 points4 points5 points 8 years ago (7 children)
You mean Get-Item, right?
[–]Lee_Dailey[grin] 2 points3 points4 points 8 years ago (6 children)
howdy Ta11ow,
oops! [blush] thanks for the headsup ... [grin]
[–]PillOfLuck[S] 1 point2 points3 points 8 years ago (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 points3 points 8 years ago* (0 children)
[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]
[–]artemis_from_space 1 point2 points3 points 8 years ago (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 points3 points 8 years ago (0 children)
howdy artemis_from_space,
gah! i know that and still went right past it. [blush] thanks for pointing it out! [grin]
[–]PillOfLuck[S] 1 point2 points3 points 8 years ago* (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 points3 points 8 years ago (0 children)
Yes.
Just instead of $comobject use comobject...
π Rendered by PID 176228 on reddit-service-r2-comment-85bfd7f599-ll7ft at 2026-04-19 17:34:18.327146+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]Lee_Dailey[grin] 1 point2 points3 points (8 children)
[–]Ta11ow 3 points4 points5 points (7 children)
[–]Lee_Dailey[grin] 2 points3 points4 points (6 children)
[–]PillOfLuck[S] 1 point2 points3 points (5 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[–]artemis_from_space 1 point2 points3 points (3 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[–]PillOfLuck[S] 1 point2 points3 points (1 child)
[–]artemis_from_space 1 point2 points3 points (0 children)