title = "Continue?"
$message = "If the settings are correct, Press Y to Continue?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Yes"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "No"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$choice=$host.ui.PromptForChoice($title, $message, $options, 1)
if ($choice -eq 1){Write-Warning "You pressed no. Exiting script routine.";break}
Else { 'Do something Special }
Tips, tricks, and scripts for Admins on the run. Also this serves a a brainless repository for me when I know I'll need it later.
Tuesday, April 21, 2015
Use User Credentials in MDT 2013 to Run Powershell Script
#UserName $tmpuser=$tsenv:UserID $tmpuser=[System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String($tmpuser)) #DomainName $tmpdomain=$tsenv:UserDomain $tmpdomain=[System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String($tmpdomain)) #set password to variable $tmppassword=$tsenv:UserPassword #Decode Password [string]$tmppassword=[System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String($tmppassword)) #Convert to secure string $mypassword=ConvertTo-SecureString -String $tmppassword -AsPlainText -Force #format domainname\username for PSCredential object [string]$tmpFQusername=$tmpdomain + "\" + $tmpuser $creds = new-object System.Management.Automation.PSCredential($tmpFQusername,$mypassword)
Place the above code into your custom scripts to use PScredentials
Labels:
invalid username or password,
MDT,
new-psdrive,
powershell,
pscredentials,
UNC
Monday, April 13, 2015
Living List of Hotfixes for various components at Microsoft.
Subscribe to:
Posts (Atom)