PowerShell正在读取属性文件

PowerShell正在读取属性文件,powershell,powershell-2.0,Powershell,Powershell 2.0,我需要从配置文件读取属性。 我可以用它来做 ConvertFrom-StringData(Get-Content test.conf | out-String) 但在这个文件中我有一个参数 username=intranet\sysTestAcc 当它试图解析它时,我出现了错误: 无法识别的转义序列\s 我如何用脚本解决这个问题?在运行脚本之前,我无法更改文件 您必须使用另一个逃逸\。i、 e username=intranet\\sysTestAcc 在这一点上,StringData的转

我需要从配置文件读取属性。 我可以用它来做

ConvertFrom-StringData(Get-Content test.conf | out-String)
但在这个文件中我有一个参数

username=intranet\sysTestAcc
当它试图解析它时,我出现了错误: 无法识别的转义序列\s


我如何用脚本解决这个问题?在运行脚本之前,我无法更改文件

您必须使用另一个逃逸\。i、 e

username=intranet\\sysTestAcc
在这一点上,StringData的转换器将很高兴


您还可以使用“-Raw”参数来获取内容,而不是管道输入输出字符串。

您必须使用另一个参数来转义\。i、 e

username=intranet\\sysTestAcc
在这一点上,StringData的转换器将很高兴


您还可以使用“-Raw”参数来获取内容,而不是管道输入输出字符串。

\
替换为
\

# The first '\\' is a regex with a '\' escape to create a literal '\'
# The second '\\' is a literal replacement (non-regex) that inserts two '\'
ConvertFrom-StringData ((Get-Content test.conf -Raw) -replace '\\','\\')

\
替换为
\

# The first '\\' is a regex with a '\' escape to create a literal '\'
# The second '\\' is a literal replacement (non-regex) that inserts two '\'
ConvertFrom-StringData ((Get-Content test.conf -Raw) -replace '\\','\\')

我不能,因为我有第一个版本的Powershell。问题是在运行脚本之前我不能替换。我不能,因为我有第一个版本的Powershell。问题是在运行脚本之前我不能替换。