forked from Vidanez/DeployVMs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorecredentials.ps1
More file actions
14 lines (14 loc) · 822 Bytes
/
Storecredentials.ps1
File metadata and controls
14 lines (14 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#STORED CREDENTIAL CODE
$AdminName = Read-Host "Enter your Admin AD username"
$CredsFile = "C:\usercredentials.txt"
$FileExists = Test-Path $CredsFile
if ($FileExists -eq $false) {
Write-Host 'Credential file not found. Enter your password:' -ForegroundColor Red
Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File $CredsFile
$password = get-content $CredsFile | convertto-securestring
$Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist domain\$AdminName,$password}
else
{Write-Host 'Using your stored credential file' -ForegroundColor Green
$password = get-content $CredsFile | convertto-securestring
$Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist domain\$AdminName,$password}
#END OF STORED CREDENTIAL CODE