升级到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 the path is correct
and try again.
At line:1 char:1
+ ConvertTo-SecureString
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ConvertTo-SecureString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
我发现PS 3.0上的ConvertTo-SecureString是supported。我需要以某种方式包括它吗?
答案 0 :(得分:0)
Import-Module 'Microsoft.PowerShell.Security'
解决了这个问题。我不知道为什么默认情况下不加载此模块。
答案 1 :(得分:0)
以下内容无效。
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>
我将说明为什么它不能作为其他人的命令使用,因为我只是超级用户。
S。