Windows Powershell转换为SecureString ObjectNotFound
升级到powershell 3.0后,现有脚本停止工作,但出现错误Windows Powershell转换为SecureString ObjectNotFound,windows,powershell,powershell-3.0,Windows,Powershell,Powershell 3.0,升级到powershell 3.0后,现有脚本停止工作,但出现错误 ConvertTo-SecureString : The term 'ConvertTo-SecureString' 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
ConvertTo-SecureString : The term 'ConvertTo-SecureString' 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:1
+ ConvertTo-SecureString
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ConvertTo-SecureString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
我发现ConvertToSecureString在PS3.0上。我是否需要以某种方式包含它
Import-Module 'Microsoft.PowerShell.Security'
解决了这个问题。我不知道为什么默认情况下不加载此模块。以下操作不起作用
C:\contoso>powershell -command {$secured='random text'|ConvertTo-SecureString -AsPlainText -Force;$secured;}
'ConvertTo-SecureString' is not recognized as an internal or external command,
operable program or batch file.
C:\contoso>
以下方法确实有效
C:\contoso>copy con: tfile1.ps1
$secured='random text'|ConvertTo-SecureString -AsPlainText -Force;
$secured;
^Z
1 file(s) copied.
C:\contoso>powershell -file tfile1.ps1
System.Security.SecureString
C:\contoso>
这也行得通
C:\contoso>powershell "& {$secured='random text'|ConvertTo-SecureString -AsPlainText -Force;$secured}"
System.Security.SecureString
C:\contoso>
我将把它为什么不能作为命令使用留给其他人,因为我只是一个powershell新手
S.所有脚本都停止工作了吗?还是仅包含
ContertTo SecureString
的脚本?在我的3.0版上,相应的DLL位于此处C:\Windows\Microsoft.Net\assembly\GAC\MSIL\Microsoft.PowerShell.Security\v4.0\U 3.0.0.0\UUUU 31bf3856ad364e35\Microsoft.PowerShell.Security.DLL
。您可以检查该dll是否位于该路径。您还应该有以下目录:C:\Windows\System32\windowsupershell\v1.0\modules\Microsoft.PowerShell.Security
BTW您在哪个操作系统上?您是否安装了任何服务器产品,如Exchange、SharePoint server、SCCM等?导入执行时没有显示错误,但没有为我解决问题。您的回答与上述问题无关,但我来到这里是因为我认为我遇到了与您相同的问题(使用cmd或PS中的ConvertTo SecureString
调用PS). 您的解决方法并不是基于您使用其他变量这一事实,而是基于您在更深层调用命令这一事实。为了澄清这一点,这也将起作用:powershell“&{converttosecurestring-AsPlainText'random text'-Force}”