我正在使用Invoke-WebRequest来获取HtmlWebResponseObject对象。我想获取ID字段的值,当描述字段匹配特定字符串时(在这种情况下," server1")。 Invoke-WebRequest返回了数百个结果(因此字符串超长)鉴于下面的示例,我将如何提取ID?
{ "状态":200, "数据":[ { " nextRecipient":0, " clearSent":是的, " lastSentNotificationOn":0, " netscanVersion":" 0", " suppressAlertClear":" false", " build":" 19000", " lastSentNotificationOnLocal":"", " id":6, " resendIval":15, " watchdogUpdatedOn":" 2016-04-11 10:28:02 MDT", "升级链接":6, " description":" domain \ server1", " ackComment":"", "凭证2":"", " updatedOn":1460392096, " updatedOnLocal":" 2016-04-11 10:28:16 MDT", " agentConf":" product.code = {guid} \ r \ n#安装程序版本,不得修改\ r \ n \ ninstaller.version = 0001 \ r \ n \ r \ n#生成按代理配置向导\ r \ nserver = url \ r \ n ncompany = company \ r \ nid = 6 \ r \ n ncredential == cred \ r \ n \ r \ n#logger设置。将logger.size设置为0,对记录器大小没有限制,否则,大小限制为由\ r \ nlogger.output = console \ r \ n \ nlogger.logfile = \ r \ n \ nlogger.size = 64 \ r \ nlogger指定的字节数。 level = info \ r \ n \ r \ n#watchdog log level \ r \ nlogger.watchdog = info \ r \ n#每个组件,在这里添加更详细的控件\ r \ n#eg \ r \ n#logger.level.controller = debug \ r \ n#\ r \ n#如果没有设置,它将使用默认日志级别,即logger.level的值\ r \ n#\ r \ n \ r \ n \ n #if if agent应该监视看门狗,默认为false \ r \ n \ nntagemonitorwatchdog = true \ r \ n \ r \ n#是否看门狗升级代理,默认为true \ r \ n \ nntage.autoupgrade = true \ r \ n \ r \ n#服务连接超时。连接默认为5秒,发送/读取服务器的默认值为30秒\ r \ n服务.connect_timeout = 5 \ r \ n \ n服务.read_timeout = 30 \ r \ n \ r \ n#SSL&代理设置\ r \ n \ nssl.enable = true \ r \ nproxy.enable = false \ r \ nproxy.host = \ r \ n \ nproxy.port = \ r \ n \ nproxy.user = \ r \ n \ nproxy.pass = \ r \ n \ nproxy .exclude = \ r \ n \ r \ n#sbproxy settings \ r \ nsbproxy.address = 127.0.0.1 \ r \ nsbproxy.port = 72 \ r \ nsbproxy.logsize = 64 \ r \ nsbproxy.restartOn102 = false \ r \ n \ nsbproxy.pdhNoAuthentication = false \ r \ n \ r \ n#sbproxy连接池设置\ r \ nsbproxy.pool.connections = 50 \ r
感谢。
答案 0 :(得分:5)
将响应从JSON字符串转换为对象并展开相关属性:
$response | ConvertFrom-Json |
Select-Object -Expand data |
Where-Object { $_.description -match 'server1' } |
Select-Object -Expand id