Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

How to view the value of a Secure.string variable

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-28-2008   #1 (permalink)
Flea#
Guest


 

How to view the value of a Secure.string variable

Hello,

I am asking a user to enter their password for use in a script. I am saying
$password = Read-Host "Enter Password" - asSecureString

This now puts it into a SecureString variable. When I call the variable, it
just returns System.Security.SecureString. Does anyone know how to extract
the actual string from the variable?

Thanks,
Flea#
--
http://fleasharp.blogspot.com/

My System SpecsSystem Spec
Old 01-28-2008   #2 (permalink)
Brandon Shell [MVP]
Guest


 

Re: How to view the value of a Secure.string variable

Try this

function GetSecurePass ($SecurePassword) {
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($SecurePassword)
$pwd = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
$pwd
}

GetSecurePass $password

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

F> Hello,
F>
F> I am asking a user to enter their password for use in a script. I am
F> saying $password = Read-Host "Enter Password" - asSecureString
F>
F> This now puts it into a SecureString variable. When I call the
F> variable, it just returns System.Security.SecureString. Does anyone
F> know how to extract the actual string from the variable?
F>
F> Thanks,
F> Flea#


My System SpecsSystem Spec
Old 01-28-2008   #3 (permalink)
Kiron
Guest


 

Re: How to view the value of a Secure.string variable

$password = Read-Host "Enter Password" -asSecureString

[Runtime.InteropServices.Marshal]::PtrToStringAuto[Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))

--
Kiron
My System SpecsSystem Spec
Old 01-28-2008   #4 (permalink)
Shay Levi
Guest


 

Re: How to view the value of a Secure.string variable



You've missed the opening parenthesis
Quote:
Quote:

>> ...([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> $password = Read-Host "Enter Password" -asSecureString
>
> [Runtime.InteropServices.Marshal]::PtrToStringAuto[Runtime.InteropServ
> ices.Marshal]::SecureStringToBSTR($password))
>

My System SpecsSystem Spec
Old 01-28-2008   #5 (permalink)
Kiron
Guest


 

Re: How to view the value of a Secure.string variable

Last post had a typo:

[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))

--
Kiron
My System SpecsSystem Spec
Old 01-28-2008   #6 (permalink)
Shay Levi
Guest


 

Re: How to view the value of a Secure.string variable



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Thanks Shay.
>

My System SpecsSystem Spec
Old 01-28-2008   #7 (permalink)
Kiron
Guest


 

Re: How to view the value of a Secure.string variable

Thanks Shay.

--
Kiron
My System SpecsSystem Spec
Old 01-28-2008   #8 (permalink)
Flea#
Guest


 

Re: How to view the value of a Secure.string variable

That worked perfectly, thanks Kiron.
--
http://fleasharp.blogspot.com/


"Kiron" wrote:
Quote:

> Last post had a typo:
>
> [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
>
> --
> Kiron
My System SpecsSystem Spec
Old 01-29-2008   #9 (permalink)
alexandair
Guest


 

Re: How to view the value of a Secure.string variable

On Jan 29, 12:20*am, Brandon Shell [MVP] <a_bshell.m...@xxxxxx>
wrote:
Quote:

> Try this
>
> function GetSecurePass ($SecurePassword) {
> * $Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($S*ecurePassword)
> * $pwd = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
> * [System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
> * $pwd
>
> }
>
> GetSecurePass $password
>
> Brandon Shell
> ---------------
> Blog:http://www.bsonposh.com/
> PSH Scripts Project: *www.codeplex.com/psobject
>
> F> Hello,
> F>
> F> I am asking a user to enter their password for use in a script. I am
> F> saying $password = Read-Host "Enter Password" - asSecureString
> F>
> F> This now puts it into a SecureString variable. When I call the
> F> variable, it just returns System.Security.SecureString. Does anyone
> F> know how to extract the actual string from the variable?
> F>
> F> Thanks,
> F> Flea#
To keep in mind, $pwd is the built-in variable containing the path to
the current working directory, so if you use this variable name, it
overwrites the $pwd automatic variable.

-aleksandar
http://powershellers.blogspot.com
My System SpecsSystem Spec
Old 01-29-2008   #10 (permalink)
Brandon Shell [MVP]
Guest


 

Re: How to view the value of a Secure.string variable

Duh... I usually used $password so I just change to $pwd when I pasted without
thinking. Good catch.

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

a> On Jan 29, 12:20 am, Brandon Shell [MVP] <a_bshell.m...@xxxxxx>
a> wrote:
a>
Quote:
Quote:

>> Try this
>>
>> function GetSecurePass ($SecurePassword) {
>> $Ptr =
>> [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnic
>> ode($S*ecurePassword)
>> $pwd = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
>> [System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($P
>> tr)
>> $pwd
>> }
>>
>> GetSecurePass $password
>>
>> Brandon Shell
>> ---------------
>> Blog:http://www.bsonposh.com/
>> PSH Scripts Project: www.codeplex.com/psobject
>> F> Hello,
>> F>
>> F> I am asking a user to enter their password for use in a script. I
>> am
>> F> saying $password = Read-Host "Enter Password" - asSecureString
>> F>
>> F> This now puts it into a SecureString variable. When I call the
>> F> variable, it just returns System.Security.SecureString. Does
>> anyone
>> F> know how to extract the actual string from the variable?
>> F>
>> F> Thanks,
>> F> Flea#
a> To keep in mind, $pwd is the built-in variable containing the path to
a> the current working directory, so if you use this variable name, it
a> overwrites the $pwd automatic variable.
a>
a> -aleksandar
a> http://powershellers.blogspot.com


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a string within a variable string Edward.A.Gonzalez PowerShell 4 08-15-2008 08:13 AM
Re: how to tokenize a string into a variable via regex Kiron PowerShell 1 07-14-2008 02:39 PM
SSIS - string variable! Daniel .NET General 0 05-15-2008 05:53 AM
Subject: using a Variable with/in a string DonP PowerShell 2 02-27-2008 02:11 PM
Using group-object with a variable string Marco Shaw PowerShell 4 12-13-2006 10:47 AM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media 2005-2008