Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Convert-ToSecureString fails on PS Core 7 Preview 4 - Previously working on PS Core 6.1 and WP 5.x #10561

Copy link
Copy link
@johnmccrae

Description

@johnmccrae
Issue body actions

Decrypt an encrypted password

            $KeyFile = "$ENV:UserProfile\.pass\aes.key"
            $Key = Get-Content $KeyFile
        $datafile = Join-Path -Path $PsScriptRoot -ChildPath 'encryptedthings.csv'

        (import-csv $datafile) |
            Foreach-Object {

            if($_.AccountPassword)
                {
                    $Securestring = ConvertTo-SecureString $_.AccountPassword -Key $key
                    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Securestring)
                    $DecryptedPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
                }
            else {
                $DecryptedPassword = ''
            }

Expected behavior

This code snippet works and has been working for some time on Windows PowerShell 5.x and PowerShell Core 6.x on OSX and Linux.

Actual behavior

ConvertTo-SecureString : Input string was not in a correct format.
At C:\Program Files\PowerShell\Modules\mymodule\0.0.0.2\Public\Get-stuff.ps1:53 char:37
+ ...   $Securestring = ConvertTo-SecureString $_.AccountPassword -Key $key
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [ConvertTo-SecureString], FormatException
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.4
PSEdition                      Core
GitCommitId                    7.0.0-preview.4
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.