gpt4 book ai didi

powershell - 请求帮助来解析字符串

转载 作者:行者123 更新时间:2023-12-03 00:36:37 25 4
gpt4 key购买 nike

我正在使用Invoke-WebRequest取回HtmlWebResponseObject对象。当描述字段与特定字符串(在本例中为“server1”)匹配时,我想获取ID字段的值。 Invoke-WebRequest返回了数百个结果(因此字符串超长)给定以下示例,我将如何提取ID?

{ "status": 200, "data": [ { "nextRecipient": 0, "clearSent": true, "lastSentNotificationOn": 0, "netscanVersion": "0", "suppressAlertClear": "false", "build": "19000", "lastSentNotificationOnLocal": "", "id": 6, "resendIval": 15, "watchdogUpdatedOn": "2016-04-11 10:28:02 MDT", "escalatingChainId": 6, "description": "domain\server1", "ackComment": "", "credential2": "", "updatedOn": 1460392096, "updatedOnLocal": "2016-04-11 10:28:16 MDT", "agentConf": "product.code={guid}\r\n# Installer version, Shall not be modified\r\ninstaller.version=0001\r\n\r\n# Generated by Agent Configuration Wizard\r\nserver=url\r\ncompany=company\r\nid=6\r\ncredential==cred\r\n\r\n# logger settings. Set logger.size to 0 to no limitation on logger size, otherwise, size limited to Mbytes specified by that\r\nlogger.output=console\r\nlogger.logfile=\r\nlogger.size=64\r\nlogger.level=info\r\n\r\n#watchdog log level\r\nlogger.watchdog=info\r\n# for each component, add more detailed control here\r\n# e.g. \r\n# logger.level.controller=debug\r\n#\r\n# if not set, it will use default log level, i.e. value of logger.level\r\n#\r\n\r\n#if agent shall watch watchdog, default to false\r\nagentmonitorwatchdog=true\r\n\r\n#whether watchdog upgrades agent, default to true\r\nagent.autoupgrade=true\r\n\r\n#service connection timeouts. Default to 5 seconds for connecting and 30 seconds for sending / reading feeds from server\r\nservice.connect_timeout=5\r\nservice.read_timeout=30\r\n\r\n#SSL & Proxy settings\r\nssl.enable=true\r\nproxy.enable=false\r\nproxy.host= \r\nproxy.port=\r\nproxy.user=\r\nproxy.pass=\r\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\nsbproxy.pdhNoAuthentication=false\r\n\r\n#sbproxy connection pool settings\r\nsbproxy.pool.connections=50\r



谢谢。

最佳答案

将响应从JSON字符串转换为对象,然后展开相关属性:

$response | ConvertFrom-Json |
Select-Object -Expand data |
Where-Object { $_.description -match 'server1' } |
Select-Object -Expand id

关于powershell - 请求帮助来解析字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36554756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com