Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell ConvertTo-SecureString ObjectNotFound

After upgrading to powershell 3.0 existing scripts stopped working with an error

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

I found that ConvertTo-SecureString is supported on PS 3.0. Do I need to include it somehow?

like image 213
Sly Avatar asked Nov 20 '25 17:11

Sly


1 Answers

The following does NOT work.

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>

The following does work.

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> 

This also works.

C:\contoso>powershell "& {$secured='random text'|ConvertTo-SecureString -AsPlainText -Force;$secured}"
System.Security.SecureString

C:\contoso>

I'll leave why it doesn't work as a -command to someone else as I'm only a powershell novice.

S.

like image 112
Sean Robinson Avatar answered Nov 22 '25 08:11

Sean Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!