@@ -23,7 +23,7 @@ function Invoke-NinjaOneTenantSync {
23
23
$EndDate = try { Get-Date ($CurrentItem.lastEndTime ) } catch { $Null }
24
24
25
25
if (($null -ne $CurrentItem.lastStartTime ) -and ($StartDate -gt (Get-Date ).ToUniversalTime().AddMinutes(-10 )) -and ( $Null -eq $CurrentItem.lastEndTime -or ($StartDate -gt $EndDate ))) {
26
- Throw " NinjaOne Sync for Tenant $ ( $MappedTenant.RowKey ) is still running, please wait 10 minutes and try again."
26
+ throw " NinjaOne Sync for Tenant $ ( $MappedTenant.RowKey ) is still running, please wait 10 minutes and try again."
27
27
}
28
28
29
29
# Set Last Start Time
@@ -45,10 +45,10 @@ function Invoke-NinjaOneTenantSync {
45
45
$Customer = Get-Tenants - IncludeErrors | Where-Object { $_.customerId -eq $MappedTenant.RowKey }
46
46
Write-Information " Processing: $ ( $Customer.displayName ) - Queued for $ ( (New-TimeSpan - Start $StartQueueTime - End $StartTime ).TotalSeconds) "
47
47
48
- Write-LogMessage - API ' NinjaOneSync ' - Headers ' NinjaOneSync' - message " Processing NinjaOne Synchronization for $ ( $Customer.displayName ) - Queued for $ ( (New-TimeSpan - Start $StartQueueTime - End $StartTime ).TotalSeconds) " - Sev ' Info'
48
+ Write-LogMessage - tenant $Customer .defaultDomainName - API ' NinjaOneSync' - message " Processing NinjaOne Synchronization for $ ( $Customer.displayName ) - Queued for $ ( (New-TimeSpan - Start $StartQueueTime - End $StartTime ).TotalSeconds) " - Sev ' Info'
49
49
50
50
if (($Customer | Measure-Object ).count -ne 1 ) {
51
- Throw " Unable to match the recieved ID to a tenant QueueItem: $ ( $QueueItem | ConvertTo-Json - Depth 100 | Out-String ) Matched Customer: $ ( $Customer | ConvertTo-Json - Depth 100 | Out-String ) "
51
+ throw " Unable to match the recieved ID to a tenant QueueItem: $ ( $QueueItem | ConvertTo-Json - Depth 100 | Out-String ) Matched Customer: $ ( $Customer | ConvertTo-Json - Depth 100 | Out-String ) "
52
52
}
53
53
54
54
$TenantFilter = $Customer.defaultDomainName
@@ -303,7 +303,7 @@ function Invoke-NinjaOneTenantSync {
303
303
304
304
$MaxSecureScore = $CurrentSecureScore.maxScore
305
305
306
- [System.Collections.Generic.List [PSCustomObject ]]$SecureScoreParsed = Foreach ($Score in $CurrentSecureScore.controlScores ) {
306
+ [System.Collections.Generic.List [PSCustomObject ]]$SecureScoreParsed = foreach ($Score in $CurrentSecureScore.controlScores ) {
307
307
$MatchedProfile = $SecureScoreProfiles | Where-Object { $_.id -eq $Score.controlName }
308
308
[PSCustomObject ]@ {
309
309
Category = $Score.controlCategory
@@ -448,7 +448,7 @@ function Invoke-NinjaOneTenantSync {
448
448
}
449
449
450
450
# Parse Devices
451
- Foreach ($Device in $Devices | Where-Object { $_.id -notin $ParsedDevices.id }) {
451
+ foreach ($Device in $Devices | Where-Object { $_.id -notin $ParsedDevices.id }) {
452
452
453
453
# First lets match on serial
454
454
$MatchedNinjaDevice = $NinjaDevices | Where-Object { $_.system.biosSerialNumber -eq $Device.SerialNumber -or $_.system.serialNumber -eq $Device.SerialNumber }
@@ -489,7 +489,7 @@ function Invoke-NinjaOneTenantSync {
489
489
490
490
491
491
492
- Foreach ($DeviceUser in $Device.usersloggedon ) {
492
+ foreach ($DeviceUser in $Device.usersloggedon ) {
493
493
$FoundUser = ($Users | Where-Object { $_.id -eq $DeviceUser.userid })
494
494
$DeviceUsers.add ($FoundUser.DisplayName )
495
495
$DeviceUserIDs.add ($DeviceUser.userId )
@@ -753,7 +753,7 @@ function Invoke-NinjaOneTenantSync {
753
753
754
754
$NinjaOneUser = $NinjaOneUserDocs | Where-Object { $_.ParsedFields.cippUserID -eq $User.ID }
755
755
if (($NinjaOneUser | Measure-Object ).count -gt 1 ) {
756
- Throw ' Multiple Users with the same ID found'
756
+ throw ' Multiple Users with the same ID found'
757
757
}
758
758
759
759
@@ -847,7 +847,7 @@ function Invoke-NinjaOneTenantSync {
847
847
}
848
848
849
849
# OS Icon
850
- $OSIcon = Switch ($UserDevice.OS ) {
850
+ $OSIcon = switch ($UserDevice.OS ) {
851
851
' Windows' { ' <i class="fab fa-windows"></i>' }
852
852
' iOS' { ' <i class="fab fa-apple"></i>' }
853
853
' Android' { ' <i class="fab fa-android"></i>' }
@@ -1180,7 +1180,7 @@ function Invoke-NinjaOneTenantSync {
1180
1180
Remove-AzDataTableEntity - Force @UsersUpdateTable - Entity $NinjaUserCreation
1181
1181
[System.Collections.Generic.List [PSCustomObject ]]$NinjaUserCreation = @ ()
1182
1182
}
1183
- } Catch {
1183
+ } catch {
1184
1184
Write-Information " Bulk Creation Error, but may have been successful as only 1 record with an issue could have been the cause: $_ "
1185
1185
}
1186
1186
@@ -1192,7 +1192,7 @@ function Invoke-NinjaOneTenantSync {
1192
1192
Remove-AzDataTableEntity - Force @UsersUpdateTable - Entity $NinjaUserUpdates
1193
1193
[System.Collections.Generic.List [PSCustomObject ]]$NinjaUserUpdates = @ ()
1194
1194
}
1195
- } Catch {
1195
+ } catch {
1196
1196
Write-Information " Bulk Update Errored, but may have been successful as only 1 record with an issue could have been the cause: $_ "
1197
1197
}
1198
1198
@@ -1255,7 +1255,7 @@ function Invoke-NinjaOneTenantSync {
1255
1255
Remove-AzDataTableEntity - Force @UsersUpdateTable - Entity $NinjaUserCreation
1256
1256
1257
1257
}
1258
- } Catch {
1258
+ } catch {
1259
1259
Write-Information " Bulk Creation Error, but may have been successful as only 1 record with an issue could have been the cause: $_ "
1260
1260
}
1261
1261
@@ -1266,7 +1266,7 @@ function Invoke-NinjaOneTenantSync {
1266
1266
[System.Collections.Generic.List [PSCustomObject ]]$UpdatedUsers = (Invoke-WebRequest - Uri " https://$ ( $Configuration.Instance ) /api/v2/organization/documents" - Method PATCH - Headers @ {Authorization = " Bearer $ ( $token.access_token ) " } - ContentType ' application/json; charset=utf-8' - Body (" [$ ( $NinjaUserUpdates.body -join ' ,' ) ]" ) - EA Stop).content | ConvertFrom-Json - Depth 100
1267
1267
Remove-AzDataTableEntity - Force @UsersUpdateTable - Entity $NinjaUserUpdates
1268
1268
}
1269
- } Catch {
1269
+ } catch {
1270
1270
Write-Information " Bulk Update Errored, but may have been successful as only 1 record with an issue could have been the cause: $_ "
1271
1271
}
1272
1272
@@ -1311,10 +1311,10 @@ function Invoke-NinjaOneTenantSync {
1311
1311
1312
1312
1313
1313
# Relate Users to Devices
1314
- Foreach ($LinkDevice in $ParsedDevices | Where-Object { $null -ne $_.NinjaDevice }) {
1314
+ foreach ($LinkDevice in $ParsedDevices | Where-Object { $null -ne $_.NinjaDevice }) {
1315
1315
$RelatedItems = (Invoke-WebRequest - Uri " https://$ ( $Configuration.Instance ) /api/v2/related-items/with-entity/NODE/$ ( $LinkDevice.NinjaDevice.id ) " - Method GET - Headers @ {Authorization = " Bearer $ ( $token.access_token ) " } - ContentType ' application/json' ).content | ConvertFrom-Json - Depth 100
1316
1316
[System.Collections.Generic.List [PSCustomObject ]]$Relations = @ ()
1317
- Foreach ($LinkUser in $LinkDevice.UserIDs ) {
1317
+ foreach ($LinkUser in $LinkDevice.UserIDs ) {
1318
1318
$MatchedUser = $UsersMap | Where-Object { $_.M365ID -eq $LinkUser }
1319
1319
if (($MatchedUser | Measure-Object ).count -eq 1 ) {
1320
1320
$ExistingRelation = $RelatedItems | Where-Object { $_.relEntityType -eq ' DOCUMENT' -and $_.relEntityId -eq $MatchedUser.NinjaOneID }
@@ -1338,7 +1338,7 @@ function Invoke-NinjaOneTenantSync {
1338
1338
$Null = Invoke-WebRequest - Uri " https://$ ( $Configuration.Instance ) /api/v2/related-items/entity/NODE/$ ( $LinkDevice.NinjaDevice.id ) /relations" - Method POST - Headers @ {Authorization = " Bearer $ ( $token.access_token ) " } - ContentType ' application/json' - Body ($Relations | ConvertTo-Json - Depth 100 - AsArray) - EA Stop
1339
1339
Write-Information ' Completed Update'
1340
1340
}
1341
- } Catch {
1341
+ } catch {
1342
1342
Write-Information " Creating Relations Failed: $_ "
1343
1343
}
1344
1344
}
@@ -1449,7 +1449,7 @@ function Invoke-NinjaOneTenantSync {
1449
1449
Write-Information ' Creating NinjaOne Licenses'
1450
1450
[System.Collections.Generic.List [PSCustomObject ]]$CreatedLicenses = (Invoke-WebRequest - Uri " https://$ ( $Configuration.Instance ) /api/v2/organization/documents" - Method POST - Headers @ {Authorization = " Bearer $ ( $token.access_token ) " } - ContentType ' application/json; charset=utf-8' - Body ($NinjaLicenseCreation | ConvertTo-Json - Depth 100 - AsArray) - EA Stop).content | ConvertFrom-Json - Depth 100
1451
1451
}
1452
- } Catch {
1452
+ } catch {
1453
1453
Write-Information " Bulk Creation Error, but may have been successful as only 1 record with an issue could have been the cause: $_ "
1454
1454
}
1455
1455
@@ -1460,21 +1460,21 @@ function Invoke-NinjaOneTenantSync {
1460
1460
[System.Collections.Generic.List [PSCustomObject ]]$UpdatedLicenses = (Invoke-WebRequest - Uri " https://$ ( $Configuration.Instance ) /api/v2/organization/documents" - Method PATCH - Headers @ {Authorization = " Bearer $ ( $token.access_token ) " } - ContentType ' application/json; charset=utf-8' - Body ($NinjaLicenseUpdates | ConvertTo-Json - Depth 100 - AsArray) - EA Stop).content | ConvertFrom-Json - Depth 100
1461
1461
Write-Information ' Completed Update'
1462
1462
}
1463
- } Catch {
1463
+ } catch {
1464
1464
Write-Information " Bulk Update Errored, but may have been successful as only 1 record with an issue could have been the cause: $_ "
1465
1465
}
1466
1466
1467
1467
[System.Collections.Generic.List [PSCustomObject ]]$LicenseDocs = $CreatedLicenses + $UpdatedLicenses
1468
1468
1469
1469
if ($Configuration.LicenseDocumentsEnabled -eq $True -and $Configuration.UserDocumentsEnabled -eq $True ) {
1470
1470
# Relate Subscriptions to Users
1471
- Foreach ($LinkLic in $LicenseDetails ) {
1471
+ foreach ($LinkLic in $LicenseDetails ) {
1472
1472
$MatchedLicDoc = $LicenseDocs | Where-Object { $_.documentName -eq $LinkLic.name }
1473
1473
if (($MatchedLicDoc | Measure-Object ).count -eq 1 ) {
1474
1474
# Remove existing relations
1475
1475
$RelatedItems = (Invoke-WebRequest - Uri " https://$ ( $Configuration.Instance ) /api/v2/related-items/with-entity/DOCUMENT/$ ( $MatchedLicDoc.documentId ) " - Method GET - Headers @ {Authorization = " Bearer $ ( $token.access_token ) " } - ContentType ' application/json' ).content | ConvertFrom-Json - Depth 100
1476
1476
[System.Collections.Generic.List [PSCustomObject ]]$Relations = @ ()
1477
- Foreach ($LinkUser in $LinkLic.Users ) {
1477
+ foreach ($LinkUser in $LinkLic.Users ) {
1478
1478
$ExistingRelation = $RelatedItems | Where-Object { $_.relEntityType -eq ' DOCUMENT' -and $_.relEntityId -eq $LinkUser }
1479
1479
if (! $ExistingRelation ) {
1480
1480
$Relations.Add (
@@ -1494,7 +1494,7 @@ function Invoke-NinjaOneTenantSync {
1494
1494
$Null = Invoke-WebRequest - Uri " https://$ ( $Configuration.Instance ) /api/v2/related-items/entity/DOCUMENT/$ ( $ ($MatchedLicDoc.documentId )) /relations" - Method POST - Headers @ {Authorization = " Bearer $ ( $token.access_token ) " } - ContentType ' application/json' - Body ($Relations | ConvertTo-Json - Depth 100 - AsArray) - EA Stop
1495
1495
Write-Information ' Completed Update'
1496
1496
}
1497
- } Catch {
1497
+ } catch {
1498
1498
Write-Information " Creating Relations Failed: $_ "
1499
1499
}
1500
1500
@@ -2126,7 +2126,7 @@ function Invoke-NinjaOneTenantSync {
2126
2126
$CurrentItem | Add-Member - NotePropertyName lastStatus - NotePropertyValue ' Completed' - Force
2127
2127
Add-CIPPAzDataTableEntity @MappingTable - Entity $CurrentItem - Force
2128
2128
2129
- Write-LogMessage - API ' NinjaOneSync ' - Headers ' NinjaOneSync' - message " Completed NinjaOne Sync for $ ( $Customer.displayName ) . Queued for $ ( (New-TimeSpan - Start $StartQueueTime - End $StartTime ).TotalSeconds) seconds. Data fetched in $ ( (New-TimeSpan - Start $StartTime - End $FetchEnd ).TotalSeconds) seconds. Total processing time $ ( (New-TimeSpan - Start $StartTime - End (Get-Date )).TotalSeconds) seconds" - Sev ' info'
2129
+ Write-LogMessage - tenant $Customer .defaultDomainName - API ' NinjaOneSync' - message " Completed NinjaOne Sync for $ ( $Customer.displayName ) . Queued for $ ( (New-TimeSpan - Start $StartQueueTime - End $StartTime ).TotalSeconds) seconds. Data fetched in $ ( (New-TimeSpan - Start $StartTime - End $FetchEnd ).TotalSeconds) seconds. Total processing time $ ( (New-TimeSpan - Start $StartTime - End (Get-Date )).TotalSeconds) seconds" - Sev ' info'
2130
2130
2131
2131
} catch {
2132
2132
$Message = if ($_.ErrorDetails.Message ) {
@@ -2136,7 +2136,7 @@ function Invoke-NinjaOneTenantSync {
2136
2136
$_.Exception.message
2137
2137
}
2138
2138
Write-Error " Failed NinjaOne Processing for $ ( $Customer.displayName ) Linenumber: $ ( $_.InvocationInfo.ScriptLineNumber ) Error: $Message "
2139
- Write-LogMessage - API ' NinjaOneSync ' - Headers ' NinjaOneSync' - message " Failed NinjaOne Processing for $ ( $Customer.displayName ) Linenumber: $ ( $_.InvocationInfo.ScriptLineNumber ) Error: $Message " - Sev ' Error'
2139
+ Write-LogMessage - tenant $Customer .defaultDomainName - API ' NinjaOneSync' - message " Failed NinjaOne Processing for $ ( $Customer.displayName ) Linenumber: $ ( $_.InvocationInfo.ScriptLineNumber ) Error: $Message " - Sev ' Error'
2140
2140
$CurrentItem | Add-Member - NotePropertyName lastEndTime - NotePropertyValue ([string ]$ ((Get-Date ).ToUniversalTime().ToString(' yyyy-MM-ddTHH:mm:ss.fffZ' ))) - Force
2141
2141
$CurrentItem | Add-Member - NotePropertyName lastStatus - NotePropertyValue ' Failed' - Force
2142
2142
Add-CIPPAzDataTableEntity @MappingTable - Entity $CurrentItem - Force
0 commit comments