Hi Jason,
This line is a mixture of two different foreach methods, it uses the foreach-object
(used in pipelines) cmdlet with the foreach statement syntax (which is totaly
wrong):
foreach-object ($result in $results) {...
Make it look like:
foreach ($result in $results) {...
You can get more help on this here:
PS > help about_foreach
As for the __properties, this members are attached to every WMI result, use
select-object to select only the properties you need.
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
J> So I'm following along this training CBT, and the following function
J> comes up:
J> #######################
J> function where-pingable {
J> PROCESS {
J> $results = get-wmiobject -query "Select statuscode from
J> win32_pingstatus
J> where address = '$_'"
J> foreach-object ($result in $results) {
J> if ($result.Statuscode -eq 0) {
J> write-host $_
J> break
J> }
J> }
J> }
J> }
J> #####################
J> But when I try to add the function to the environment, I get:
J> PS C:\> . ./test.ps1
J> Unexpected token 'in' in expression or statement.
J> At C:\test.ps1:4 char:31
J> + foreach-object ($result in <<<< $results) {
J> So I tried to figure out what's going on. When I test the gwmi
J> portion of
J> this function with a single IP address:
J> #############
J> get-wmiobject -query "Select statuscode from win32_pingstatus where
J> address
J> = '10.131.1.66'"
J> #############
J> I get:
J> __GENUS : 2
J> __CLASS : Win32_PingStatus
J> __SUPERCLASS :
J> __DYNASTY :
J> __RELPATH :
J> __PROPERTY_COUNT : 1
J> __DERIVATION : {}
J> __SERVER :
J> __NAMESPACE :
J> __PATH :
J> StatusCode : 0
J> My first question is why aren't I getting just the StatusCode back
J> like I asked for? Why am I getting this other junk?
J>
J> Thank you for your patience in helping the newbie! -Jason
J>