Skip to content

Instantly share code, notes, and snippets.

@KelvinTegelaar
Created September 15, 2020 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KelvinTegelaar/b70ea12e44843d35f386334b9e70fff5 to your computer and use it in GitHub Desktop.
Save KelvinTegelaar/b70ea12e44843d35f386334b9e70fff5 to your computer and use it in GitHub Desktop.
######### Secrets #########
$ApplicationId = 'AppID'
$ApplicationSecret = 'AppSecret' | ConvertTo-SecureString -Force -AsPlainText
$RefreshToken = 'RefreshToken'
$APIKEy = "LangeITGlueAPIKeyHier"
$APIEndpoint = "https://api.eu.itglue.com"
######### Secrets #########
$CustomerTenant = "Client.onmicrosoft.com"
$ITGlueORGID = "123456"
########################## Script Settings ############################
If (Get-Module -ListAvailable -Name "ITGlueAPI") {
Import-module ITGlueAPI
}
Else {
Install-Module ITGlueAPI -Force
Import-Module ITGlueAPI
}
#Settings IT-Glue logon information
Add-ITGlueBaseURI -base_uri $APIEndpoint
Add-ITGlueAPIKey $APIKEy
$Baseuri = "https://graph.microsoft.com/beta"
write-host "Generating token to log into Azure AD. Grabbing all tenants" -ForegroundColor Green
$credential = New-Object System.Management.Automation.PSCredential($ApplicationId, $ApplicationSecret)
$CustGraphToken = New-PartnerAccessToken -ApplicationId $ApplicationId -Credential $credential -RefreshToken $refreshToken -Scopes "https://graph.microsoft.com/.default" -ServicePrincipal -Tenant $CustomerTenant
write-host "$($Tenant.Displayname): Starting process." -ForegroundColor Green
$Header = @{
Authorization = "Bearer $($CustGraphToken.AccessToken)"
}
write-host "Finding devices in $($CustomerTenant)" -ForegroundColor Green
$devicesList = (Invoke-RestMethod -Uri "$baseuri/devices" -Headers $Header -Method get -ContentType "application/json").value | Where-Object { $_.Operatingsystem -ne "Windows" }
$Configurationtype = (Get-ITGlueConfigurationTypes).data | Select-Object ID -ExpandProperty attributes | Out-GridView -PassThru -Title "Select a configuration type"
$Configurationstatus = (Get-ITGlueConfigurationStatuses).data | Select-Object ID -ExpandProperty attributes | Out-GridView -PassThru -Title "Select a status type"
$manafacture = (Get-ITGlueManufacturers).data | Select-Object ID -ExpandProperty attributes | Out-GridView -PassThru -Title "Select a manufacturer"
foreach ($device in $devicesList) {
$Existing = Get-ITGlueConfigurations -filter_serial_number $device.deviceId
if ($Existing) { write-host "$($device.displayname) exists, skipping."; continue }
$dataobj = @{
type = "configurations"
attributes = @{
"organization-id" = $ITGlueOrgID
"name" = $device.displayName
"configuration-type-id" = $configurationtype.id
"configuration-status-id" = $Configurationstatus.id
"manufacturer-id" = $manafacture.id
"serial-number" = $device.deviceId
}
}
New-ITGlueConfigurations -organization_id $ITGlueORGID -data $dataobj
$dataobj = $null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment