繁体   English   中英

Powershell 表格和计数

[英]Powershell Tables & Counts

命令Get-RDUserSession为我提供了服务器连接用户的完美视图,甚至 Session State。 但我想将这些输出分组到一个新变量中

我喜欢的是 Output

ServerName(this Should be Unieque)|TotalAmmountofConnected Users witch is an Adition of State_Active,State_Connected,Session_Disconnected 
|SessionState(State_Active this in Count)| SessionState(State_Connected this in Count)| SessionState(State_Disconnected this in count)

我努力了:

$Value = Get-RDUserSession -CollectionName Colection -ConnectionBroker ConnectionBroker
$Value | Group-Object -Property ServerName,SessionState | Where-Object {$_.Count} | Select Name,Count

我不知道如何对这些值进行分组或将它们分开。 我真的需要一些帮助......

这是一个示例 Output:

ServerName                 SessionState
Server1.domain.com       STATE_ACTIVE
Server1.domain.com       STATE_ACTIVE
Server1.domain.com       STATE_ACTIVE
Server1.domain.com       STATE_ACTIVE
Server1.domain.com       STATE_ACTIVE
Server1.domain.com       STATE_ACTIVE
Server1.domain.com       STATE_CONNECTED
Server3.domain.com       STATE_ACTIVE
Server3.domain.com       STATE_ACTIVE
Server3.domain.com       STATE_DISCONNECTED
Server3.domain.com       STATE_ACTIVE
Server3.domain.com       STATE_CONNECTED
Server3.domain.com       STATE_ACTIVE
Server3.domain.com       STATE_ACTIVE
Server2.domain.com       STATE_ACTIVE
Server2.domain.com       STATE_CONNECTED
Server2.domain.com       STATE_CONNECTED
Server2.domain.com       STATE_CONNECTED
Server2.domain.com       STATE_ACTIVE
Server7.domain.com       STATE_ACTIVE
Server7.domain.com       STATE_ACTIVE
Server7.domain.com       STATE_DISCONNECTED

尝试计算每个组的 Group 属性中的属性:

$Value = Get-RDUserSession -CollectionName Colection -ConnectionBroker ConnectionBroker
$Value | 
    sort ServerName |
    Group ServerName |
    Select Name,
        @{l='TotalUsers';       e={($_.group.SessionState).count}},
        @{l='ConnectedUsers';   e={($_.group.SessionState | where {$_ -like 'State_Active'}).count}},
        @{l='DisconnectedUsers';e={($_.group.SessionState | where {$_ -like 'State_Disconnected'}).count}}
$Value = Get-RDUserSession -CollectionName Colection -ConnectionBroker ConnectionBroker
$Overview = $Value | 
    sort ServerName |
    Group ServerName |
    Select Name,
        @{l='Total'; e={($_.group.SessionState).count}},
        @{l='State_Active'; e={($_.group.SessionState | where {$_ -like 'State_Active'}).count}},
        @{l='State_Connected';e={($_.group.SessionState | where {$_ -like 'State_Connected'}).count}},
        @{l='State_Disconnected';e={($_.group.SessionState | where {$_ -like 'State_Disconnected'}).count}}

$overview | ft -AutoSize

谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM