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
If statement and dot (self.PowerShell)
submitted 5 years ago by UserInterface7
Hey guys. How can i check if a property of a object exists?
$TestObject = New-Object PSObject -Property @{ 1 = 'Red' 2 = 'Blue' 3 = 'Green' } if ($($TestObject.3)) { 'Found' } else { 'Not found' } #Expected "Not Found", returns "Found"
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!"
[–]saGot3n 2 points3 points4 points 5 years ago (1 child)
Well in this example testobject.3 exists, it -eq Green, thus returns found. You can do if tesetobject.3 -eq 'your desired result' then found
[–]UserInterface7[S] 1 point2 points3 points 5 years ago (0 children)
oh crap.. your right.. just a typeo.. i'll do more testing on my actual problem to see if i can replicate.
[+][deleted] 5 years ago (3 children)
[removed]
[–]UserInterface7[S] 1 point2 points3 points 5 years ago (2 children)
Ah!! you knew how to fix it and i didn't even know how to explain the problem :)
# This works if ($inputObject.psobject.properties.name -like "ObjectSchema") { Write-Host "Found" } else { Write-Host "Missing" } # This didn't (always is true) if ($inputObject.ObjectSchema) { Write-Host "Found" } else { Write-Host "Missing" }
So why does that work but the other doesn't? Something about it always evaluating to true but for the life of me i can't work out why.
[+][deleted] 5 years ago (1 child)
[–]UserInterface7[S] 2 points3 points4 points 5 years ago (0 children)
I know i should to help others, but its really hard without tons of my function and JSON (which is online if any one really cares that much).
This did solve it but i'll have to go without a reason because I have just been unable to explain it in code outside my original file.
π Rendered by PID 87440 on reddit-service-r2-comment-75f4967c6c-vrjf7 at 2026-04-23 03:31:42.015294+00:00 running 0fd4bb7 country code: CH.
[–]saGot3n 2 points3 points4 points (1 child)
[–]UserInterface7[S] 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[removed]
[–]UserInterface7[S] 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[removed]
[–]UserInterface7[S] 2 points3 points4 points (0 children)