Skip to content

Commit 432e2e8

Browse files
authored
Merge pull request #291 from bepsoccer/release
Enhances Access user management and documentation
2 parents 31dec2f + ef6df5e commit 432e2e8

16 files changed

Lines changed: 1534 additions & 14 deletions

docs/examples/AC_Profile_picture_import.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Say you want to bulk import AC profile pictures by dropping them in a folder and naming the image files using a unique identifier. The first the first thing you need to do is authenticate:
44

55
```powershell
6-
Connect-Verkada -org_id [your_orgId] -x_api_key (Get-Secret -Name VrkdApiKey -AsPlainText)
6+
Connect-Verkada -x_api_key (Get-Secret -Name VrkdApiKey -AsPlainText)
77
88
#or for simplicity when not using secrets.
99
10-
Connect-Verkada -org_id [your_orgId] -x_api_key [your_api_key]
10+
Connect-Verkada -x_api_key [your_api_key]
1111
```
1212

1313
>Then if you've named the image files using the user's **user_id**, like fc6c3648-aa4a-4999-b1a0-a64b81e2cb76.jpg, you can use something like this:
@@ -26,7 +26,7 @@ or
2626
2727
or
2828
29-
>If you've named the image files using the user's **email**, like some.user@contoso.com.jpg, we will need to find the user_id to set the picture with something like this:
29+
>If you've named the image files using the user's **email**, like `some.user@contoso.com.jpg`, we will need to find the user_id to set the picture with something like this:
3030
>
3131
>```powershell
3232
>Get-ChildItem ~/Documents/AC_profile_pictures | ForEach-Object {$temp = $_; read-VerkadaAccessUsers -version v1 -refresh | Where-Object {$_.email -eq $temp.BaseName} | Set-VerkadaAccessUserProfilePicture -imagePath $temp.FullName; $temp = $null}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Merge Duplicate AC Users
2+
3+
Say you want to find duplicate AC users and merge their group membership, cards, and profile pictures. First thing to do is to get an export of the AC users from Command. Then, add a new field to the CSV, **duplicate_userId**. Then we will use that CSV for the import in the script.
4+
5+
```powershell
6+
Connect-Verkada -x_api_key (Get-Secret -Name VrkdApiKey -AsPlainText)
7+
8+
#or for simplicity when not using secrets.
9+
10+
Connect-Verkada -x_api_key [your_api_key]
11+
```
12+
13+
After connecting, we will import the user CSV and create our logic for determining duplicate Ids and which user we want to live on.
14+
15+
```powershell
16+
# import users
17+
$exportedUsers = Import-Csv ~/command-user-export.csv
18+
19+
# find users with emails that have duplicate users with the same first and last names
20+
# this logic can be changed to meet the needs to determine duplicates
21+
foreach ($user in $exportedUsers){
22+
if (!([string]::IsNullOrEmpty($user.email))){
23+
$user.duplicate_userId = $exportedUsers | Where-Object {[string]::IsNullOrEmpty($_.email) -and $_.firstName -ieq $user.firstName -and $_.lastName -ieq $user.lastName} | Select-Object -ExpandProperty userId
24+
}
25+
}
26+
$duplicateSCIMusers = $exportedUsers | Where-Object {!([string]::IsNullOrEmpty($_.duplicate_userId))}
27+
```
28+
29+
Once we have the duplicate_userId field added to our CSV the logic below will describe what will be done in the output and perform it in Command.
30+
31+
```powershell
32+
Start-Transcript -Path ~/transcript_output.txt
33+
$doWork = $false
34+
foreach ($dupe in $duplicateSCIMusers){
35+
foreach ($dupeId in $dupe.duplicate_userId){
36+
# determine if duplicate is active
37+
if ($dupe.status -ieq 'active'){
38+
if (($exportedUsers | Where-Object {$_.userId -eq $dupeId}).status -ieq 'active'){
39+
write-host "$($dupe.firstName) $($dupe.lastName) - $($dupe.userId) SCIM user is active and has the duplicate account $($dupeId) for us to work on"
40+
$doWork = $true
41+
} else {
42+
write-host "Will do nothing, $($dupe.firstName) $($dupe.lastName) - $($dupe.userId) SCIM user is active but the duplicate account $($dupeId) is $(($exportedUsers | Where-Object {$_.userId -eq $dupeId}).status)."
43+
$doWork = $false
44+
}
45+
} else {
46+
if (($exportedUsers | Where-Object {$_.userId -eq $dupeId}).status -ieq 'active'){
47+
write-host "$($dupe.firstName) $($dupe.lastName) - $($dupe.userId) SCIM user is $($dupe.status) but the duplicate account $($dupeId) is active, what should we do?"
48+
$doWork = $false
49+
} else {
50+
write-host "Will do nothing, Neither $($dupe.firstName) $($dupe.lastName) - $($dupe.userId) SCIM user or the duplicate account $($dupeId) is active."
51+
$doWork = $false
52+
}
53+
}
54+
55+
if($doWork){
56+
# gather all the groups the duplicate is a part of
57+
try {
58+
$groups = Get-VerkadaAccessUser -userId $dupeId -ErrorAction Stop | Select-Object -ExpandProperty access_groups
59+
Write-host "$($dupeId) is part of the following AC Groups: $($groups.name -join ',')"
60+
$scimUserGroups = Get-VerkadaAccessUser -userId $dupe.userId | Select-Object -ExpandProperty access_groups | Select-Object -ExpandProperty group_id
61+
foreach ($group in $groups){
62+
# determine if the user is already apart of that group
63+
If ($scimUserGroups -contains $group.group_id ){
64+
Write-Host "$($dupe.firstName) $($dupe.lastName) - $($dupe.userId) is already a part of $($group.name) and doesn't need to be added"
65+
} else {
66+
Write-Host "$($dupe.firstName) $($dupe.lastName) - $($dupe.userId) needs to be added to $($group.name)"
67+
# add user to group if necessary
68+
Set-VerkadaAccessUserGroup -userId $dupe.userId -groupId $group.group_id
69+
}
70+
}
71+
$scimUserGroups = $null
72+
} catch {
73+
$groups = @()
74+
Write-Host "$($dupeId) is not part of any AC groups"
75+
}
76+
77+
# gather all the cards the duplicate has
78+
$cards = Get-VerkadaAccessUser -userId $dupeId | Select-Object -ExpandProperty cards | Where-Object {$_.active -eq $true}
79+
if ([string]::IsNullOrEmpty($cards)){
80+
Write-Host "$($dupeId) has no active cards to move"
81+
} else {
82+
Write-host "$($dupeId) has the following cards to move to $($dupe.firstName) $($dupe.lastName) - $($dupe.userId): $($cards.card_number -join ',')"
83+
# assign those cards to the SCIM user
84+
foreach ($card in $cards){
85+
Add-VerkadaAccessUserCard -userId $dupe.userId -cardType $card.type -cardNumber $card.card_number -facilityCode $card.facility_code -active $true
86+
}
87+
}
88+
89+
# determine if duplicate has a photo and the SCIM user doesn't
90+
if (!(Get-VerkadaAccessUser -userId $dupe.userId | Select-Object -ExpandProperty has_profile_photo)){
91+
if (Get-VerkadaAccessUser -userId $dupeId | Select-Object -ExpandProperty has_profile_photo){
92+
Write-Host "$($dupeId) has a profile photo to copy to $($dupe.firstName) $($dupe.lastName) - $($dupe.userId)"
93+
# get profile photo
94+
Get-VerkadaAccessUserProfilePicture -userId $dupeId -original $true -outPath ~/Downloads/tempPics/
95+
96+
# add profile photo to SCIM user
97+
Set-VerkadaAccessUserProfilePicture -userId $dupe.userId -imagePath "~/Downloads/tempPics/$dupeId.jpg"
98+
}
99+
}
100+
# deactivtate the duplicate user
101+
Set-VerkadaAccessUserEndDate -userId $dupeId -endDate (Get-Date)
102+
}
103+
$doWork = $false
104+
105+
Write-Host ""
106+
}
107+
108+
}
109+
Stop-Transcript
110+
```

docs/examples/Using_secrets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ If you need to retrieve an API key and submit it as plain text.
66

77
```powershell
88
$vrkdApiKey = Get-Secret -Name VrkdApiKey -AsPlainText
9-
Connect-Verkada -org_id [your_orgId] -x_api_key $vrkdApiKey
9+
Connect-Verkada -x_api_key $vrkdApiKey
1010
1111
#or
1212
13-
Connect-Verkada -org_id [your_orgId] -x_api_key (Get-Secret -Name VrkdApiKey -AsPlainText)
13+
Connect-Verkada -x_api_key (Get-Secret -Name VrkdApiKey -AsPlainText)
1414
```
1515

1616
If you need to retrieve a user password and submit it as a SecureString.

docs/function-documentation/Access/Read-VerkadaAccessUsers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ Gathers all Access Users in an organization via the legacy private API or using
1212

1313
## SYNTAX
1414

15+
### v1 (Default)
16+
```
17+
Read-VerkadaAccessUsers [-x_verkada_auth_api <String>] [-region <String>] [-refresh] [-version <String>]
18+
[-errorsToFile] [-ProgressAction <ActionPreference>] [<CommonParameters>]
19+
```
20+
1521
### legacy
1622
```
1723
Read-VerkadaAccessUsers [[-query] <Object>] [[-variables] <Object>] [-region <String>]
1824
[-x_verkada_token <String>] [-x_verkada_auth <String>] [-usr <String>] [-refresh] [-minimal]
1925
[-version <String>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
2026
```
2127

22-
### v1
23-
```
24-
Read-VerkadaAccessUsers [-x_verkada_auth_api <String>] [-region <String>] [-refresh] [-version <String>]
25-
[-errorsToFile] [-ProgressAction <ActionPreference>] [<CommonParameters>]
26-
```
27-
2828
## DESCRIPTION
2929
This function will return all the active Access users in an organization.
3030
The org_id and reqired tokens can be directly submitted as parameters, but is much easier to use Connect-Verkada to cache this information ahead of time and for subsequent commands.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
external help file: verkadaModule-help.xml
3+
Module Name: verkadaModule
4+
online version: https://github.com/bepsoccer/verkadaModule/blob/master/docs/function-documentation/Connect-Verkada.md
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertFrom-PropertylessJson
9+
10+
## SYNOPSIS
11+
{{ Fill in the Synopsis }}
12+
13+
## SYNTAX
14+
15+
```
16+
ConvertFrom-PropertylessJson [[-Object1] <Object>] [[-keyProperty] <String>]
17+
[-ProgressAction <ActionPreference>] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
{{ Fill in the Description }}
22+
23+
## EXAMPLES
24+
25+
### Example 1
26+
```powershell
27+
PS C:\> {{ Add example code here }}
28+
```
29+
30+
{{ Add example description here }}
31+
32+
## PARAMETERS
33+
34+
### -Object1
35+
{{ Fill Object1 Description }}
36+
37+
```yaml
38+
Type: Object
39+
Parameter Sets: (All)
40+
Aliases:
41+
42+
Required: False
43+
Position: 0
44+
Default value: None
45+
Accept pipeline input: False
46+
Accept wildcard characters: False
47+
```
48+
49+
### -keyProperty
50+
{{ Fill keyProperty Description }}
51+
52+
```yaml
53+
Type: String
54+
Parameter Sets: (All)
55+
Aliases:
56+
57+
Required: False
58+
Position: 1
59+
Default value: None
60+
Accept pipeline input: False
61+
Accept wildcard characters: False
62+
```
63+
64+
### -ProgressAction
65+
{{ Fill ProgressAction Description }}
66+
67+
```yaml
68+
Type: ActionPreference
69+
Parameter Sets: (All)
70+
Aliases: proga
71+
72+
Required: False
73+
Position: Named
74+
Default value: None
75+
Accept pipeline input: False
76+
Accept wildcard characters: False
77+
```
78+
79+
### CommonParameters
80+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
81+
82+
## INPUTS
83+
84+
### None
85+
## OUTPUTS
86+
87+
### System.Object
88+
## NOTES
89+
90+
## RELATED LINKS
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
external help file: verkadaModule-help.xml
3+
Module Name: verkadaModule
4+
online version: https://github.com/bepsoccer/verkadaModule/blob/master/docs/function-documentation/Find-VerkadaUserId.md
5+
schema: 2.0.0
6+
---
7+
8+
# Get-AddressCheck
9+
10+
## SYNOPSIS
11+
Used to verify an address with Google Maps API and retrieve lat/lon
12+
13+
## SYNTAX
14+
15+
```
16+
Get-AddressCheck [-address] <String> [-key <String>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
17+
```
18+
19+
## DESCRIPTION
20+
Private function to verify an address with Google Maps API and retrieve lat/lon
21+
22+
## EXAMPLES
23+
24+
### Example 1
25+
```powershell
26+
PS C:\> {{ Add example code here }}
27+
```
28+
29+
{{ Add example description here }}
30+
31+
## PARAMETERS
32+
33+
### -address
34+
The url for the enpoint to be used
35+
36+
```yaml
37+
Type: String
38+
Parameter Sets: (All)
39+
Aliases:
40+
41+
Required: True
42+
Position: 1
43+
Default value: None
44+
Accept pipeline input: False
45+
Accept wildcard characters: False
46+
```
47+
48+
### -key
49+
Google Maps API Key
50+
51+
```yaml
52+
Type: String
53+
Parameter Sets: (All)
54+
Aliases:
55+
56+
Required: False
57+
Position: Named
58+
Default value: AIzaSyBOqayI1MPP1zWM_MiP-Hjq3gR9144jqvM
59+
Accept pipeline input: False
60+
Accept wildcard characters: False
61+
```
62+
63+
### -ProgressAction
64+
{{ Fill ProgressAction Description }}
65+
66+
```yaml
67+
Type: ActionPreference
68+
Parameter Sets: (All)
69+
Aliases: proga
70+
71+
Required: False
72+
Position: Named
73+
Default value: None
74+
Accept pipeline input: False
75+
Accept wildcard characters: False
76+
```
77+
78+
### CommonParameters
79+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
80+
81+
## INPUTS
82+
83+
## OUTPUTS
84+
85+
## NOTES
86+
87+
## RELATED LINKS

0 commit comments

Comments
 (0)