This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
reactivateUsers.ps1
137 lines (107 loc) · 4.18 KB
/
reactivateUsers.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<#
.SYNOPSIS
Reactivates all users in a Qlik Sense Site that have been set to inactive and removed externally.
.DESCRIPTION
Connects to the Qlik Sense Repository using the QRS API. A POST selection call is run with a filter on inactive eq true, then a PUT on the selection is made to change the properties to false.
.EXAMPLE
Reactivate-QlikUsers %senseServerHostName% %certFriendlyName%
.EXAMPLE
Reactivate-QlikUsers sense3.112adams.local QlikClient
.Parameter senseServerHostName
The name of the Qlik Sense server.
.Parameter certFriendlyName
The friendly name of the Qlik Sense generated certificate used to connect to the QRS api.
This Code defaults to using the CurrentUser certificate store and prefers using the QlikClient certificate. The QlikClient certificate is installed for the service account user set up during Qlik Sense installation.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$senseServerHostName,
[Parameter(Mandatory=$true)][string]$certFriendlyName
)
<# Hardcoded Parameters to make things move faster when testing
request parameters in command line can be uncommented above and then
comment below
$senseServerHostName = "https://%senseServerHostName%"
$senseVirtualProxy = "%VirtualProxyPrefix%"
$virtualProxyHeader = "%HeaderName%"
$userId = "%Admin User%"
$certFriendlyName = "%certFriendlyName%"
#>
#Find Certificate
$ns = "System.Security.Cryptography.X509Certificates"
$store = New-Object "$ns.X509Store"("My","CurrentUser")
$store.Open("ReadOnly")
ForEach($cert in $store.Certificates)
{
if($cert.FriendlyName -eq $certFriendlyName)
{
$certToUse = $cert
}
}
$protocol = "https://"
$senseServerHostName = $protocol + $senseServerHostName + ":4242"
function QRSConnect {
param (
[Parameter(Position=0,Mandatory=$true)]
[string] $command,
[Parameter(Position=1,Mandatory=$true)]
[System.Collections.Generic.Dictionary`2[System.String,System.String]] $header,
[Parameter(Position=2,Mandatory=$true)]
[string] $method,
[Parameter(Position=3,Mandatory=$true)]
[System.Object] $cert,
[Parameter(Position=4,Mandatory=$false)]
[System.Object] $body
)
$contenttype = "application/json"
if($method -eq "PUT")
{
$response = Invoke-RestMethod $command -ContentType $contenttype -Headers $header -Method $method -Certificate $cert -Body $body
}
else
{
$response = Invoke-RestMethod $command -Headers $header -Method $method -Certificate $cert
}
return $response
}
# cross site scripting key
$xrfKey = "ABCDEFG123456789"
# Create a dictionary object that allows header storage in Rest call
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-Qlik-Xrfkey",$xrfKey)
$headers.Add("X-Qlik-User", "UserDirectory=internal;UserId=sa_repository")
#Get a selection object for all inactive users
$filter = "&filter=inactive eq true"
$path = "/selection/user?xrfkey=$xrfKey"
$theCommand = $senseServerHostName + "/qrs" + $path + $filter
$selection = QRSConnect $theCommand $headers "POST" $certToUse
Write-Host $selection.id
$path = "/selection/" + $selection.id + "/user/synthetic?xrfkey=$xrfKey"
$theCommand = $senseServerHostName + "/qrs" + $path
$modDate = (Get-Date).AddDays(1)
$modDate = Get-Date -Date $modDate -format s
Write-Host $modDate
$body = "{
'properties':
[
{
'name':'inactive',
'value':false,
'valueIsDifferent':true,
'valueIsModified':true
},
{
'name':'removedExternally',
'value':false,
'valueIsDifferent':true,
'valueIsModified':true
}
],
'type':'User',
'latestModifiedDate':'$modDate.999Z'
}"
Write-Host $body
QRSConnect $theCommand $headers "PUT" $certToUse $body
$path = "/selection/" + $selection.id + "?xrfkey=$xrfKey"
$theCommand = $senseServerHostName + "/qrs" + $path
QRSConnect $theCommand $headers "DELETE" $certToUse $body