Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
Powershell 如何读取文本文件中定义的参数值_Powershell_Azure_Azure Powershell - Fatal编程技术网

Powershell 如何读取文本文件中定义的参数值

Powershell 如何读取文本文件中定义的参数值,powershell,azure,azure-powershell,Powershell,Azure,Azure Powershell,我正在使用下面的命令读取txt文件中定义的参数值 $asid = Get-Content -Path config.cfg | Select-String -Pattern 'NW_GetSid' | ForEach-Object { $_.line.split('= ') } 该参数在文件中定义如下: Hostname = hostname NW_GetSid = ABC 该命令首先给出空行输出,然后输出: Blank line ABC 我怎样才能避免结果中的空行,如在输出中,我只需要

我正在使用下面的命令读取txt文件中定义的参数值

$asid = Get-Content -Path config.cfg | Select-String -Pattern 'NW_GetSid' | ForEach-Object { $_.line.split('= ') }
该参数在文件中定义如下:

Hostname = hostname
NW_GetSid = ABC
该命令首先给出空行输出,然后输出:

Blank line
ABC

<>我怎样才能避免结果中的空行,如在输出中,我只需要<代码> ABC <代码>来存储在ASID变量中?

< p>我会用正则表达式检索你想要的属性

的值。

$asid = [regex]::Match((get-content config.cfg -Raw), 'NW_GetSid\s*=\s*(\w+)').Groups[1].Value