-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuagreadonlyacct
More file actions
49 lines (36 loc) · 1.73 KB
/
Copy pathuagreadonlyacct
File metadata and controls
49 lines (36 loc) · 1.73 KB
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
####################################################################
# Create ready-only account in the VMware Unified Access Gateway Appliance
# for monitoring purposes using vROPS or API etc.
# Author - Aresh Sarkari (@askaresh)
# Version - V5.0
####################################################################
# Ignore UAG cert errors (self signed or
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
##API Call to make the intial connection to the UAG Appliance##
$Uri = "https://10.0.0.1:9443/rest/v1/config/adminusers/logAdminUserAction/LOGIN"
$Username = "admin"
$Password = "adminpassword"
$Headers = @{ Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username,$Password))) }
Invoke-RestMethod -SessionVariable DaLogin -Uri $Uri -Headers $Headers
###API Call to create the user account with read-only access under VMware Unified Access Gateway##
$body = @{
name = "UAG_vRops"
password= "typeyourpassword"
enabled=$true
roles = @("ROLE_MONITORING")
noOfDaysRemainingForPwdExpiry=0
} | ConvertTo-Json
$output = Invoke-RestMethod -WebSession $DaLogin -Method Put -Uri "https://10.0.0.1:9443/rest/v1/config/adminusers" -Body $body -ContentType "application/json"
Write-Output $output