【发布时间】:2020-03-19 11:21:18
【问题描述】:
我有一个 IBM Tivoli 命令的输出,它实际上是一堆键和值,看起来像这样
Name : NT_Paging_File_Warning
Full Name :
Description : Knt:KNT1340
Type : Windows OS
Formula : *IF *VALUE NT_Paging_File.%_Usage *GE 75 *AND *VALUE NT_Paging_File.%_Usage *LT 0 *AND *VALUE NT_Paging_File.Pagefile_Name_U *NE _Total
Sampling Interval : 0/0:15:0
Run At Start Up : Yes
Distribution :
Text : ADVICE("knt:"+$ISITSTSH.SITNAME$);
Action Location : Agent
Action Selection : System Command
System Command : *NONE
True For Multiple Items: Action on First Item only
TEC Severity : Warning
TEC Forwarding :
TEC Destination :
我想有效地获取该输出并将其转换为具有明显属性和值的 powershell 对象。如您所见,某些值可能为空,某些属性的名称中包含空格。 : 是键和值之间的标准分隔符。
有什么好的干净的 powershell 方法来解决这个问题?
我想这样做的原因是将这些记录作为对象发送到管道中,我将在其中使用诸如 Where-Object 之类的东西来过滤掉我想要的那些等等
【问题讨论】:
-
这能回答你的问题吗? Trouble parsing string to object with PowerShell。另请注意,由于 PowerShell 7
ConvertFrom-StringData支持-Delimiter参数。
标签: powershell tivoli