Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

Userinteraktion

published: November 26, 2014 author: Tinu tags: Userinteraktion categories: PowerShell


Benutzereingabe

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.

Benutzerausgabe

Normale Ausgabe:

write-host $name

Ausgabe in gelber Schrift:

write-host $name -ForegroundColor Yellow

← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →