Powershell引用返回的数据
我正在运行powershell命令,该命令返回以下数据:Powershell引用返回的数据,powershell,object,Powershell,Object,我正在运行powershell命令,该命令返回以下数据: InfoType Key SubKey Value -------- --- ------ ----- Replication
InfoType Key SubKey Value
-------- --- ------ -----
Replication repl_backlog_first_byte_of... 7602479450000
Replication repl_backlog_histlen 1048576
CPU used_cpu_sys 309301.44
CPU used_cpu_user 135181.55
CPU used_cpu_sys_children 0.05
CPU used_cpu_user_children 0.33
Keyspace db0 keys 302094
Keyspace db0 expires 302093
Keyspace db0 avg_ttl 7335993
我想引用InfoType键空间、键db0、子键键和值(302094)
我正在使用以下代码:
(Get-RedisInfo -InfoType Keyspace | where {$_.Key -eq "db0"}).Value
返回的数据太多:
(keys, 302094) (expires, 304073) (avg_ttl, 7369417)
我只想要302094号。如何仅引用键值
谢谢
Brad
获取RedisInfo-InfoType键空间|其中对象{($.Key-eq“db0”)-和($.Value-eq 302094)}|选择对象-ExpandProperty“Value”
。但这毫无意义。如果您已经知道值是什么,为什么还要运行管道呢?每次运行Get-RedisInfo命令时,值都会更改:)因此-($.value-eq 302094)不起作用:)然后Get-RedisInfo-InfoType键空间| Where Object{($.Key-eq'db0')-和($.SubKey-eq'keys')}选择Object-ExpandProperty“value”
?似乎$results=(Get RedisInfo-InfoType Keyspace | where{$\ Key-eq“db0”})。值返回一个元组:(keys,299354)(expires,299351)(avg_ttl,6609766)。我需要的只是第一个元组值(299354)。对如何提取这些信息有什么建议吗?我尝试了$results.keys和$results.Item1