What am I doing wrong?

Welcome Forums General PowerShell Q&A What am I doing wrong?

This topic contains 3 replies, has 2 voices, and was last updated by

 
Member
5 years, 4 months ago.

  • Author
    Posts
  • #10119
    GS

    Participant
    Points: 12
    Rank: Member

    Hello,

    I'm missing something very simple but I can not figure out what exactly I'm doing wrong. I'm trying to get to child object of another object and it fails.
    Namely workprocess object of Application pool.

    Import-Module WebAdministration
    $pools = gci IIS:\apppools
    $pools[2].WorkerProcesses[0].ProcessID

    I WorkerProcesses[0] is actully $null even though there are workerprocesses collection for that pool

  • #10121

    Member
    Points: 0
    Rank: Member

    I think what you probably need is this:

    $pools[2].WorkerProcesses.Collection[0].ProcessID

  • #10122
    GS

    Participant
    Points: 12
    Rank: Member

    +1 This works.
    I don't understand the problem though. $pool has collection of WorkerProcesses so I shall be able to access WorkerProcesses[0]. Why it does not work?

  • #10127

    Member
    Points: 0
    Rank: Member

    The workerProcesses property isn't a collection; it's an object of type Microsoft.IIs.PowerShell.Framework.ConfigurationElement. I just ran these commands to try to discover what was there:

    $pool = Get-Item IIS:\AppPools\MSExchangeSyncAppPool
    
    $pool.workerProcesses.GetType().FullName
    Get-Member -InputObject $pool.workerProcesses
    
    # Here's where I saw the NoteProperty called Collection
    
    $pool.workerProcesses.Collection.GetType().FullName
    
    # This came back as PSObject[], so I tried:
    
    $pool.workerProcesses.Collection[0].processId
    
    # and it worked.
    

The topic ‘What am I doing wrong?’ is closed to new replies.