Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 使用PowerShell和Select String解析文本的非标准文件_File_Powershell_Parsing_Powershell 2.0 - Fatal编程技术网

File 使用PowerShell和Select String解析文本的非标准文件

File 使用PowerShell和Select String解析文本的非标准文件,file,powershell,parsing,powershell-2.0,File,Powershell,Parsing,Powershell 2.0,使用文本编辑器打开Microsoft远程桌面保存的会话时,会话中包含值(要测试自己,请打开远程桌面连接,单击“选项”,然后单击“另存为”。在文本编辑器中打开生成的.rdp文件) 但是,在此处使用标准的Select String命令(在其他文件格式上使用完全相同的语法时有效): 。。。产生以下错误: 无法为空数组编制索引 在PowerShell 2.0中,是否有其他命令用于解析此类文件或任何非标准文本文件?您的模式不正确。.rdp文件中选项的语法为 name:type:value 就你而言: p

使用文本编辑器打开Microsoft远程桌面保存的会话时,会话中包含值(要测试自己,请打开远程桌面连接,单击“选项”,然后单击“另存为”。在文本编辑器中打开生成的.rdp文件)

但是,在此处使用标准的
Select String
命令(在其他文件格式上使用完全相同的语法时有效):

。。。产生以下错误:

无法为空数组编制索引


在PowerShell 2.0中,是否有其他命令用于解析此类文件或任何非标准文本文件?

您的模式不正确。.rdp文件中选项的语法为

name:type:value
就你而言:

promptcredentialonce:i:0
但是,您正在尝试将某个内容与选项名称(不存在)后的空格相匹配:

如果没有匹配项,
.Matches
属性为空,
.Group[1]
尝试对空值进行索引访问

如果需要包含类型的值,请删除空格:

promptcredentialonce:(.*)
如果只需要值,请将模式更改为以下内容:

promptcredentialonce:\w+:(.*)

@wOxxOm我已经用我正在使用的代码更新了帖子
匹配项
是一个数组,因此在PS2中你需要
匹配项[0]
或foreach/where/select对象。
promptcredentialonce:(.*)
promptcredentialonce:\w+:(.*)