OpsaC - Operating as PowerShell code
published: November 26, 2014 author: Tinu tags: Userinteraktion categories: PowerShell
Abfrage auf der Commandline:
$name = read-host ('Enter your name')
Abfrage des Passwortes auf der Commandline:
read-host -AsSecureString 'Enter the password'
Umwandeln des SecureStrings in Cleartext:
$spwd = read-host -AsSecureString "Enter the password for $($userid)"
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($spwd)
$cpwd = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Save credentials to a file
$savecreds = Get-Credential
$savecreds.GetType()
$savecreds | Export-CliXml 'C:\Temp\user.xml'
Read credentials from a file
$readcreds = Import-Clixml 'C:\Temp\user.xml'
$readcreds.GetType()
$readcreds.UserName.GetType()
$readcreds.Password.GetType()
Note that the secret used to encrypt and decrypt the data is composed of your identity and your machine identity, so the encrypted text can only be read by you, and only on the machine where it was originally encrypted.
Normale Ausgabe:
write-host $name
Ausgabe in gelber Schrift:
write-host $name -ForegroundColor Yellow