locked
Powershell: $Sessions[0..x].sessionlimit RRS feed

  • Question

  • Hi,

    I'd like to enumerate a certain values and can do this using [0..5]:

    $Sessions = Get-RDSessionCollectionConfiguration -CollectionName $collection -ConnectionBroker  $connectionbroker -LoadBalancing
    $Sessions[0..5].sessionlimit

    But how can I do this without defining final value (here 5) so it would list all items? So $Sessions[0..allitems]

    Please advise.
    J.


    Jan Hoedt

    Wednesday, November 30, 2016 10:16 AM

Answers

  • Also:

    $Sessions[0..($sessions.Count-1)].sessionlimit

    or

    $sessions | Select -expand sessionlimit

    or

    $sessions.sessionLimit # assuming object supports this.


    \_(ツ)_/


    • Edited by jrv Wednesday, November 30, 2016 2:28 PM
    • Marked as answer by janhoedt Wednesday, November 30, 2016 2:44 PM
    Wednesday, November 30, 2016 2:27 PM

All replies

  • Hi Jan,

    Can you use a foreach loop? 

    $Sessions = Get-RDSessionCollectionConfiguration -CollectionName $collection -ConnectionBroker  $connectionbroker -LoadBalancing
    
    foreach ($session in $sessions) 
      {
        ($Session).sessionlimit
      }



    Thanks, Tim. | Please remember to mark the replies as answers if they help. |

    Wednesday, November 30, 2016 10:31 AM
  • Also:

    $Sessions[0..($sessions.Count-1)].sessionlimit

    or

    $sessions | Select -expand sessionlimit

    or

    $sessions.sessionLimit # assuming object supports this.


    \_(ツ)_/


    • Edited by jrv Wednesday, November 30, 2016 2:28 PM
    • Marked as answer by janhoedt Wednesday, November 30, 2016 2:44 PM
    Wednesday, November 30, 2016 2:27 PM
  • Exactly what I was looking for, thanks!

    Jan Hoedt

    Wednesday, November 30, 2016 2:44 PM
  • Hi Jan and JRV,

    May I ask the advantage of this over a for loop? Or the use case for this?

    It is a nice solution, I don't know how to use it and would like to learn more.

    Thanks, Tim.


    Thanks, Tim. | Please remember to mark the replies as answers if they help. |

    Wednesday, November 30, 2016 9:05 PM
  • Hi Jan and JRV,

    May I ask the advantage of this over a for loop? Or the use case for this?

    It is a nice solution, I don't know how to use it and would like to learn more.

    Thanks, Tim.


    Thanks, Tim. | Please remember to mark the replies as answers if they help. |


    Basic PowerShell which allows various approaches.  No Use case but it can be useful when stating certain solutions.

    \_(ツ)_/

    Wednesday, November 30, 2016 9:09 PM