-
Notifications
You must be signed in to change notification settings - Fork 0
/
awuserget.ps1
111 lines (89 loc) · 3.19 KB
/
awuserget.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<# Gets the location tags.
.SYNOPSIS
This script gets all admins for our stuff.
.USAGE
Ensure awupdaterc.ps1 is in the same directory. This file contains
1. User to authenticate with.
2. Password for the user.
3. Token for api access.
4. The endpoint URL.
Call this script to actually retrieve the information. Options below:
.PARAMETER outputFile (optional)
This is not a required file, this just helps with printing out useful information.
.PARAMETER configFile (optional)
This is not a required file, this allows you to use a different
awupdaterc.ps1 file if need be.
#>
[CmdletBinding()]
Param(
[Parameter()]
[string]$outputFile,
[Parameter()]
[string]$configFile
)
# Set errors to silent if we are not in verbose mode.
If (!$PSCmdlet.Myinvocation.BoundParameters["Verbose"].IsPresent) {
$ErrorActionPreference = "SilentlyContinue"
}
# Set up default if configFile is not already set.
If (!$configFile) {
$configFile = ".\awupdaterc.ps1"
}
# Set up default if outputFile is not already set.
If (!$outputFile) {
$outputFile = ".\user_list.csv"
}
# Source in the config file and its settings
. $configFile
# Set our base call for the api.
$baseURL = $endpointURL + "/API/"
# Source build headers function.
. ".\buildheaders.ps1"
# Source Basic auth function.
. ".\basicauth.ps1"
# We know we're using json so set accept/content type as such.
$contentType = "application/json"
# Concatonate User information for processing.
$userInfo = $userName + ":" + $password
$restUser = Get-BasicUserForAuth $userInfo
# Get our headers
$headers = Build-Headers $restUser $tenantAPIKey $contentType $contentType
# Setup our call string to get the default staging user
$changeURL = $baseURL + "system/users/search?pageSize=10000"
# Write out information for us to know what's going on.
Write-Verbose ""
Write-Verbose "---------- Caller URL ----------";
Write-Verbose ("URL: " + $changeURL)
Write-Verbose "--------------------------------";
write-Verbose ""
# Perform request
If ($Proxy) {
If ($UserAgent) {
$request = Invoke-RestMethod -Uri $changeURL -Headers $headers -OutFile ".\temp_location.json" -Proxy $Proxy -UserAgent $UserAgent
} Else {
$request = Invoke-RestMethod -Uri $changeURL -Headers $headers -OutFile ".\temp_location.json" -Proxy $Proxy
}
} Else {
If ($UserAgent) {
$request = Invoke-RestMethod -Uri $changeURL -Headers $headers -OutFile ".\temp_location.json" -UserAgent $UserAgent
} Else {
$request = Invoke-RestMethod -Uri $changeURL -Headers $headers -OutFile ".\temp_location.json"
}
}
# As we stored all the data into a file we need to read it in.
$data = Get-Content ".\temp_location.json" -Raw | ConvertFrom-Json
# Initialize array of data to store
$dataSet = @()
# Loop our locations found.
foreach ($user in $data.Users) {
$details = @{}
$id = $user.Id.Value
$name = $user.UserName
$details = [ordered]@{
UserID = $id
UserName = $name
}
$dataset += New-Object PSObject -Property $details
}
# Create the CSV to process from.
$dataSet | Export-CSV -Path $outputFile -NoTypeInformation