Skip to content

Instantly share code, notes, and snippets.

@jworkmanjc
Last active January 20, 2021 22:33
Show Gist options
  • Save jworkmanjc/a2a462f06bd0e327602e41f55cf2453f to your computer and use it in GitHub Desktop.
Save jworkmanjc/a2a462f06bd0e327602e41f55cf2453f to your computer and use it in GitHub Desktop.
This powershell script requires the JumpCloud Powershell Module, for new systems added in the last day those systems will be added to the beforeRename group.
################################################################################
# For every system with a provisionerID, if acknowledged is false, add to the
# systemGroup "BeforeRename".
################################################################################
# Powershell script to run locally as new systems are added
# Variables
# BeforeRename System GroupID
$beforeRenameGroupID = 'replaceWithBeforeGroupID'
# After account rename group
$afterRenameGroupID = 'replaceWithAfterGroupID'
# Get systems added within the last day (change day period to select only specifc days)
$selectedSystems = Get-JCSystem -filterDateProperty created -dateFilter after -date (Get-Date).AddDays(-1)
# Get system ids in the group afterRename (we dont want to add systems we've already run rename on)
$systemsInAfterGroup = Get-JCsystemGroupMember -ByID $afterRenameGroupID | select-object { $_.to.id }
# For each system in $selectedSystems
foreach ($system in $selectedSystems) {
# acknowledge the system to remove it from the topmost system list on devices page
$headers = @{
Accept = "application/json";
'x-api-key' = $ENV:JCApiKey;
}
$body = @{
'acknowledged' = 'true'
} | ConvertTo-Json
$acknowledged = Invoke-WebRequest -Method Put -Uri "https://console.jumpcloud.com/api/systems/$($system._id)" -Headers $headers -Body $body -ContentType 'application/json' -UseBasicParsing
# Finally Add the system to the beforeRename system group
if ($systemsInAfterGroup -match $system._id) {
# Condition where the system was already in the AfterRename Group
write-host "System: $($system._id) already in AfterRename group, skipping..."
}
else{
# Add the system
Add-JCSystemGroupMember -GroupID $beforeRenameGroupID -SystemID $system._id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment