This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Update-UserPassword.ps1
67 lines (55 loc) · 2.59 KB
/
Update-UserPassword.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
function Update-UserPassword {
Param (
[Parameter(Mandatory = $true)][String]$User,
[Parameter(Mandatory = $true)][String]$OldPassword,
[Parameter(Mandatory = $true)][String]$NewPassword,
[Parameter(Mandatory=$True)][Object[]]$Array
)
##################################################################
# This function expects a connection to have already been made
# to the target array using the Pure PowerShell SDK v1. That
# array object must be passed to this function, as we use that
# to obtain endpoint and API token information
##################################################################
$baseURI = "https://" + $Array.EndPoint + "/api/1.17"
##################################################################
# Establish Connection Using API Token from SDK1 Array Variable
##################################################################
$connectURI = $baseURI + "/auth/session"
$connectBody = @{
api_token = $fa.ApiToken
}
$result = Invoke-WebRequest -Uri $connectURI -Method Post -Body $connectBody -SessionVariable pure -UseBasicParsing
##################################################################
# Update Password
##################################################################
$adminURI = $baseURI + "/admin/" + $User
$body = @{
password = $NewPassword;
old_password = $OldPassword;
}
$body = $body | convertto-json
$result = Invoke-WebRequest -Uri $adminURI -WebSession $pure -Method Put -Body $body -ContentType 'application/json' -UseBasicParsing
##################################################################
# Get and Return Updated User
##################################################################
$user=Invoke-WebRequest -uri $adminURI -Method Get -WebSession $pure -UseBasicParsing
return ConvertFrom-Json($user)
}
##################################################################
# Example Usage of the Update-UserPassword Function
##################################################################
$fa = New-PfaArray -EndPoint $my_array_IP -Credentials (Get-Credential) -IgnoreCertificateError
Update-UserPassword -Array $fa -User "jpctest" -OldPassword 'myoldpassword' -NewPassword 'mynewpassword'