-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #583 from TheJumpCloud/CUT-4112_ScheduledSuspensio…
…nLookup CUT-4112: Userstate Lookups
- Loading branch information
Showing
14 changed files
with
537 additions
and
33 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
96 changes: 96 additions & 0 deletions
96
PowerShell/JumpCloud Module/Docs/Get-JCScheduledUserstate.md
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,96 @@ | ||
--- | ||
external help file: JumpCloud-help.xml | ||
Module Name: JumpCloud | ||
online version: https://github.com/TheJumpCloud/support/wiki/Get-JcSdkEventCount | ||
schema: 2.0.0 | ||
--- | ||
|
||
# Get-JCScheduledUserstate | ||
|
||
## SYNOPSIS | ||
Returns scheduled userstate changes by state or returns a user's scheduled userstate changes | ||
|
||
## SYNTAX | ||
|
||
### BulkLookup (Default) | ||
``` | ||
Get-JCScheduledUserstate -State <String> [<CommonParameters>] | ||
``` | ||
|
||
### ByID | ||
``` | ||
Get-JCScheduledUserstate -UserId <String> [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Get-JCScheduledUserstate function allows for admins to view upcoming scheduled user suspensions or activations. You can also look up an individual user's upcoming state changes by their userID | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
```powershell | ||
Get-JCScheduledUserstate -State "SUSPENDED" | ||
``` | ||
|
||
Returns all scheduled SUSPENDED userstate changes | ||
|
||
### Example 2 | ||
```powershell | ||
Get-JCScheduledUserstate -State "ACTIVATED" | ||
``` | ||
|
||
Returns all scheduled ACTIVATED userstate changes | ||
|
||
### Example 2 | ||
```powershell | ||
Get-JCScheduledUserstate -UserID "USERID" | ||
``` | ||
|
||
Returns all scheduled userstate changes for a given userID | ||
|
||
## PARAMETERS | ||
|
||
### -State | ||
The scheduled state you'd like to query (SUSPENDED or ACTIVATED) | ||
|
||
```yaml | ||
Type: System.String | ||
Parameter Sets: BulkLookup | ||
Aliases: | ||
Accepted values: SUSPENDED, ACTIVATED | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True (ByPropertyName) | ||
Accept wildcard characters: False | ||
``` | ||
### -UserId | ||
The _id of the User which you want to lookup. | ||
UserID has an Alias of _id. | ||
```yaml | ||
Type: System.String | ||
Parameter Sets: ByID | ||
Aliases: _id, id | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True (ByPropertyName) | ||
Accept wildcard characters: False | ||
``` | ||
### CommonParameters | ||
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). | ||
## INPUTS | ||
### System.String | ||
## OUTPUTS | ||
### System.Object | ||
## NOTES | ||
## RELATED LINKS |
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
97 changes: 97 additions & 0 deletions
97
PowerShell/JumpCloud Module/Public/Users/Get-JCScheduledUserstate.ps1
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,97 @@ | ||
Function Get-JCScheduledUserstate () { | ||
[CmdletBinding(DefaultParameterSetName = 'BulkLookup')] | ||
param ( | ||
[Parameter(Mandatory, ParameterSetName = 'BulkLookup', ValueFromPipelineByPropertyName = $True, HelpMessage = "The scheduled state you'd like to query (SUSPENDED or ACTIVATED)")] | ||
[ValidateSet('SUSPENDED', 'ACTIVATED')] | ||
[string]$State, | ||
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'ByID', HelpMessage = 'The _id of the User which you want to lookup. UserID has an Alias of _id.')] | ||
[Alias('_id', 'id')] | ||
[String]$UserId | ||
) | ||
begin { | ||
Write-Verbose 'Verifying JCAPI Key' | ||
if ($JCAPIKEY.length -ne 40) { | ||
Connect-JCOnline | ||
} | ||
|
||
Write-Verbose 'Initilizing resultsArray' | ||
$resultsArrayList = New-Object -TypeName System.Collections.ArrayList | ||
|
||
Write-Verbose "Parameter Set: $($PSCmdlet.ParameterSetName)" | ||
} | ||
process { | ||
switch ($PSCmdlet.ParameterSetName) { | ||
BulkLookup { | ||
if ($state -eq 'SUSPENDED') { | ||
$scheduledUsers = Get-JcSdkBulkUserState | Where-Object State -EQ 'SUSPENDED' | ||
} else { | ||
$scheduledUsers = Get-JcSdkBulkUserState | Where-Object State -EQ 'ACTIVATED' | ||
} | ||
|
||
# If no results are found, return null | ||
if (!$scheduledUsers) { | ||
return $null | ||
} | ||
|
||
# Create SearchBody to parse users | ||
$searchUserBody = @{ | ||
filter = @{ | ||
or = @( | ||
) | ||
} | ||
fields = "firstname lastname email username _id" | ||
} | ||
|
||
# Create OR lookup for IDs | ||
$scheduledUsers | ForEach-Object { | ||
$searchUserBody.filter.or += "_id:`$eq:$($_.SystemUserId)" | ||
} | ||
|
||
# Get users | ||
$searchUsers = Search-JcSdkUser -Body $searchUserBody | ||
$searchUsers | ForEach-Object { | ||
# Get the scheduled date for the user | ||
$user = $scheduledUsers | Where-Object SystemUserID -EQ $_.Id | ||
# Convert the scheduled date to datetime (also seems to convert to local as well) | ||
$localScheduledDate = [datetime]$user.ScheduledDate | ||
# Create userResult | ||
$userResult = [pscustomobject]@{ | ||
id = $_.Id | ||
Firstname = $_.Firstname | ||
Lastname = $_.Lastname | ||
Email = $_.email | ||
Username = $_.username | ||
State = $State | ||
ScheduledDate = $localScheduledDate | ||
} | ||
$resultsArrayList.Add($userResult) | Out-Null | ||
} | ||
} | ||
ByID { | ||
# Get User's scheduled state | ||
$scheduledUser = Get-JcSdkBulkUserState -Userid $userId | ||
# User attribute lookup | ||
$user = Get-JcSdkUser -Id $userId | Select-Object firstname, lastname, email, username, id | ||
|
||
$scheduledUser | ForEach-Object { | ||
# Convert date to local | ||
$localScheduledDate = [datetime]$_.ScheduledDate | ||
# Create custom return object | ||
$userResult = [pscustomobject]@{ | ||
id = $user.Id | ||
Firstname = $user.Firstname | ||
Lastname = $user.Lastname | ||
Email = $user.email | ||
Username = $user.username | ||
State = $_.State | ||
ScheduledDate = $LocalScheduledDate | ||
} | ||
$resultsArrayList.Add($userResult) | Out-Null | ||
} | ||
} | ||
} | ||
} | ||
end { | ||
return $resultsArrayList | ||
} | ||
} |
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
Oops, something went wrong.