我是Powershell的新手,我有一个脚本来检索一些操作系统属性。 它开始...
$ntfsDisableLastAccessUpdate = (Get-ItemProperty HKLM:SystemCurrentControlSetControlFileSystem -Name NtfsDisableLastAccessUpdate | Out-String).Split("`n")[2] -replace "r",""
这似乎可以在本地运行它,但在其他地方运行时会产生以下错误:
Invoke-Expression : The term '���$ntfsDisableLastAccessUpdate' is not
recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:62
+
~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (���$ntfsDisableLastAccessUpdate
:String) [Invoke-Expression], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Co
mmands.InvokeExpressionCommand
有什么想法吗?
���
肯定是编码问题的代表。这意味着问题在于文件的保存方式和读取方式。后者是缺失的重要部分。
我不明白为什么你会在本地使用Invoke-Expression
作为你的脚本。 Invoke-Expression
处理字符串,这是否意味着您将脚本文件作为字符串读取?
无论哪种方式,从评论中看起来您都可以删除有问题的字符并继续前进。