-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…, add Sync-GSUserCache for #87 ## 2.18.0 * [Issue #87](#87) * Added: `Get-GSCourseParticipant` and `Get-GSClassroomUserProfile` now have the `Fields` parameter * Added: `Sync-GSUserCache` to create a hashtable of users for quick lookups throughout scripts * [Issue #53](#53) via [PR #108](#108) - _Thanks, [@dwrusse](https://github.com/dwrusse)!_ * Added: `Get-GSContactList` * Added: `Remove-GSContact` * Other additions via [PR #108](#108) - _Thanks, [@dwrusse](https://github.com/dwrusse)!_ * Added: `Remove-GSCalendarEvent` * Added: `New-GSGmailLabel` * Added: `Remove-GSGmailLabel`
- Loading branch information
Showing
9 changed files
with
196 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function Sync-GSUserCache { | ||
<# | ||
.SYNOPSIS | ||
Syncs your GS Users to a hashtable contained in the global scoped variable $global:GSUserCache for fast lookups in scripts. | ||
.DESCRIPTION | ||
Syncs your GS Users to a hashtable contained in the global scoped variable $global:GSUserCache for fast lookups in scripts. | ||
.PARAMETER Filter | ||
The filter to use with Get-GSUser to populate your UserCache with. | ||
Defaults to * (all users). | ||
If you'd like to limit to just Active (not suspended) users, use the following filter: | ||
"IsSuspended -eq '$false'" | ||
.PARAMETER Keys | ||
The user properties to use as keys in the Cache hash. | ||
Available values are: | ||
* PrimaryEmail | ||
* Id | ||
* Alias | ||
Defaults to all 3. | ||
.PARAMETER PassThru | ||
If $true, returns the hashtable as output | ||
.EXAMPLE | ||
Sync-GSUserCache -Filter 'IsSuspended=False' | ||
Fills the $global:GSUserCache hashtable with all active users using the default Keys. | ||
#> | ||
[CmdLetBinding()] | ||
Param ( | ||
[parameter(Mandatory = $false, Position = 0)] | ||
[String[]] | ||
$Filter = @('*'), | ||
[parameter(Mandatory = $false)] | ||
[ValidateNotNullOrEmpty()] | ||
[ValidateSet('PrimaryEmail','Id','Alias')] | ||
[String[]] | ||
$Keys = @('PrimaryEmail','Id','Alias'), | ||
[parameter(Mandatory = $false)] | ||
[Switch] | ||
$PassThru | ||
) | ||
Begin { | ||
$global:GSUserCache = @{} | ||
} | ||
Process { | ||
Write-Verbose "Syncing users to `$global:GSUserCache" | ||
Get-GSUser -Filter $Filter | ForEach-Object { | ||
if ($Keys -contains 'Id') { | ||
$global:GSUserCache[$_.Id] = $_ | ||
} | ||
if ($Keys -contains 'PrimaryEmail') { | ||
$global:GSUserCache[$_.PrimaryEmail] = $_ | ||
} | ||
if ($Keys -contains 'Alias') { | ||
foreach ($email in $_.Emails.Address) { | ||
if (-not ($global:GSUserCache.ContainsKey($email))) { | ||
$global:GSUserCache[$email] = $_ | ||
} | ||
} | ||
} | ||
} | ||
} | ||
End { | ||
if ($PassThru) { | ||
return $global:GSUserCache | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.