0

I'm attempting to create a custom PowerShell object using data from the WebAdministration module for IIS7. The object should capture the ClientIPAddress and SiteID from the GetExecuteRequest WmiMethod for Worker Processes in IIS.

$p = Get-WmiObject WorkerProcess -Namespace root\WebAdministration -ComputerName . | Invoke-WmiMethod -Name GetExecutingRequests | Select-Object -ExpandProperty OutputElement
$wpob = @()

foreach($w in $p)
{
            $webrequests = New-Object PSObject
            $webrequests | Add-Member -Type NoteProperty -Name ClientIP -Value ($w | select -ExpandProperty ClientIPAddress)
            $webrequests | Add-Member -Type NoteProperty -Name SiteID -Value ($W | select -ExpandProperty SiteID)
            $wpobj += $webrequests
        }

The Problem:

Object ($wpobj) contains the 'ClientIP' and 'SiteID' under get-member, but you cannot get those values by using $wpobj.clientip or $wpobj.siteid. Only way I could retrieve those values were to use $wpobj | select clientip or $wpobj | select siteid

Not being able to get the values for the properties in the above mentioned way makes it more difficult to sort/group the data as I can't select the values later on down the pipeline.

Anyone know what I may be missing? I have not seen this before. Only in this particular case

Robert
  • 1
  • 1
  • What do you get if you index directly? What version of powershell? Does the type of value set matter? Can you set literal strings in this loop and have it work? – Etan Reisner Jan 15 '15 at 00:14
  • What kind of objects are `clientip` and `siteid`? Maybe you need to convert them to strings when you set the values for your object. – TheMadTechnician Jan 15 '15 at 00:21
  • Your $wpobj is an array of $webrequests objects. Each $webrequests object will have the properties of ‘ClientIP' and 'SiteID'. So to get to a specific value you gave to use an index. i.e. $wpobj[0].ClientIP ; $wpobj[0].SiteID – Jan Chrbolka Jan 15 '15 at 05:24
  • Thanks for the responses. @JanChrbolka - If I use $wpobj[0].siteid it outputs the value I'm looking for, but unfortunately it doesn't output all of the values when doing $wpobj.siteid - It's as if that property doesn't exist when I do this, the column is empty. This is powershell V3 – Robert Jan 15 '15 at 09:55
  • What output would you like to get when you use $wpobj.siteid? The reason I'm asking is that maybe you should use a different type of object to store the data depending on how you want to manipulate it. – Jan Chrbolka Jan 15 '15 at 10:04
  • Here is what happens if I try to group the items in this object: `$wpobj | group-object -property ClientIP | where {$_.count -gt 1}` the output then returns the Count, Name, Group. The Name column provides the ClientIP which is fine, but the SiteID property is embedded in a type of hash table in the Group-Object, group property. How do I get this out of the Group column? – Robert Jan 15 '15 at 10:10
  • @JanChrbolka That should list all siteid values in the object, but instead it returns nothing, even though that property in Get-Member, exists. What would you suggest? – Robert Jan 15 '15 at 10:12
  • With your current setup to get all site ids do $wpobj | select siteid. Or if you want both $wpobj | select siteid clientip. Executing get-member on a container object will return the methods and properties of the child object (I'm on a mobile, so can't supply a reffetence atm) I thing this is where the confusion is. – Jan Chrbolka Jan 15 '15 at 10:23

1 Answers1

0

Solution was to upgrade Powershell to V4.0. IE.invoke won't work on earlier versions of Powershell.

Robert
  • 1
  • 1