-
Notifications
You must be signed in to change notification settings - Fork 4
/
SMApiExamples.ps1
38 lines (22 loc) · 1.33 KB
/
SMApiExamples.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
# pulling list of filenames generated by password creator
$maillist = Get-ChildItem -Path "C:\temp\*.txt" -Name
foreach ($server in $maillist) {
$mailserver = $server.TrimEnd(".txt")
# Retrieving Password
$pwdTxt = Get-Content "C:\temp\$mailserver.txt"
$securePwd = $pwdTxt | ConvertTo-SecureString
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $securePwd)
$password = $credObject.GetNetworkCredential().Password
$username = $credObject.GetNetworkCredential().UserName
# SM Authentication
$authHeaders = New-Object "System.collections.Generic.Dictionary[[String],[String]]"
$authHeaders.Add("Content-Type", "application/json")
$authBody = "{ `n `"username`": `"$username`",`n `"password`": `"$password`" `n}"
$response = Invoke-RestMethod "http://$mailserver/api/v1/auth/authenticate-user" -Method 'POST' -Headers $authHeaders -Body $authBody
# SM Access Token
$smailAuthRes = $response.accessToken
# Message Traffic Statistics Example
$statHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$statHeaders.Add("Authorization", "Bearer $smailAuthRes")
$stats = Invoke-RestMethod "http://$mailserver/api/v1/settings/sysadmin/message-traffic-statistics" -Method 'GET' -Headers $statHeaders
}