windows - Powershell ConvertTo-SecureString ObjectNotFound

标签 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 the path is correct
and try again.
At line:1 char:1
+ ConvertTo-SecureString
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (ConvertTo-SecureString:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我发现 ConvertTo-SecureString 是 supported在 PS 3.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>

我会把为什么它不能作为命令工作给其他人,因为我只是一个 powershell 新手。

S.

关于windows - Powershell ConvertTo-SecureString ObjectNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19957340/

相关文章:

powershell - 使用p0参数从Powershell调用Patch.exe

powershell - MS Flow - "Get-manager"在我的批准流程中不起作用

powershell - 使用 Powershell 检查本地用户帐户/组是否存在

powershell - PowerShell v3 中 Get-ChildItem 的 PathTooLong 错误,但不是 v2

powershell - 如何将PowerShell版本从2.0升级到3.0

windows - initdb : could not execute command, postgres.exe"--boot -x1 -F ": 没有错误

windows - CMD变量替换参数

windows - 使用 WPP 跟踪到多个 ETW 提供程序

rest - 使用自签名证书和基本身份验证的Powershell Invoke-RestMethod-是否有示例?

windows - 以编程方式更新桌面 "show window contents while dragging"设置