Skip to content

Commit

Permalink
Merge pull request #1277 from kris6673/fixes
Browse files Browse the repository at this point in the history
Refactor API scripts and update device links
  • Loading branch information
KelvinTegelaar authored Jan 29, 2025
2 parents fc7133f + 2fb2999 commit 3ceac19
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,48 @@ Function Invoke-ListAzureADConnectStatus {
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

$ExecutingUser = $Request.headers.'x-ms-client-principal'
$TenantFilter = $Request.Query.TenantFilter
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'

# Interact with query parameters or the body of the request.
$TenantFilter = $Request.Query.TenantFilter
$DataToReturn = $Request.Query.DataToReturn
Write-Host "DataToReturn: $DataToReturn"

if (($DataToReturn -eq 'AzureADConnectSettings') -or ([string]::IsNullOrEmpty($DataToReturn)) ) {
$ADConnectStatusGraph = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/organization' -tenantid $TenantFilter
#$ADConnectStatusGraph = New-ClassicAPIGetRequest -Resource "74658136-14ec-4630-ad9b-26e160ff0fc6" -TenantID $TenantFilter -Uri "https://main.iam.ad.ext.azure.com/api/Directories/ADConnectStatus" -Method "GET"
#$PasswordSyncStatusGraph = New-ClassicAPIGetRequest -Resource "74658136-14ec-4630-ad9b-26e160ff0fc6" -TenantID $TenantFilter -Uri "https://main.iam.ad.ext.azure.com/api/Directories/GetPasswordSyncStatus" -Method "GET"
$AzureADConnectSettings = [PSCustomObject]@{
dirSyncEnabled = [boolean]$ADConnectStatusGraph.onPremisesSyncEnabled
#dirSyncConfigured = [boolean]$ADConnectStatusGraph.dirSyncConfigured
#passThroughAuthenticationEnabled = [boolean]$ADConnectStatusGraph.passThroughAuthenticationEnabled
#seamlessSingleSignOnEnabled = [boolean]$ADConnectStatusGraph.seamlessSingleSignOnEnabled
numberOfHoursFromLastSync = $ADConnectStatusGraph.onPremisesLastSyncDateTime
#passwordSyncStatus = [boolean]$PasswordSyncStatusGraph
raw = $ADConnectStatusGraph
}
}

if (($DataToReturn -eq 'AzureADObjectsInError') -or ([string]::IsNullOrEmpty($DataToReturn)) ) {
$selectlist = 'id', 'displayName', 'onPremisesProvisioningErrors', 'createdDateTime'
$SelectList = 'id,displayName,onPremisesProvisioningErrors,createdDateTime'
$Types = 'Users', 'Contacts', 'Groups'

$GraphRequest = foreach ($Type in $types) {
New-GraphGetRequest -uri "https://graph.microsoft.com/beta/$($Type)?`$select=$($selectlist -join ',')" -tenantid $TenantFilter | ForEach-Object {
if ($_.id -ne $null) {
$_ | Add-Member -NotePropertyName ObjectType -NotePropertyValue $Type
$_
$GraphRequest = @(
foreach ($Type in $Types) {
@{
id = $Type.ToLower()
method = 'GET'
url = "/$Type`?`$select=$SelectList"
}
}
)

$Results = New-GraphBulkRequest -Requests $GraphRequest -tenantid $TenantFilter -verbose
$ObjectsInError = @(
foreach ($Result in $Results) {
$Type = $Result.id -replace 's$' # Remove the 's' from the end of the type name
$Result.body.value | ForEach-Object {
if ($null -ne $_.id) {
$_ | Add-Member -NotePropertyName ObjectType -NotePropertyValue $Type -PassThru
}
}
}
}
$ObjectsInError = @($GraphRequest)
)
}

if ([string]::IsNullOrEmpty($DataToReturn)) {
Expand All @@ -74,6 +77,4 @@ Function Invoke-ListAzureADConnectStatus {
Body = @($FinalObject)
})
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Set-CIPPDefaultAPDeploymentProfile {
$APIName = 'Add Default Enrollment Status Page'
)

$User = $request.headers.'x-ms-client-principal-name'
$User = $request.headers.'x-ms-client-principal'

try {
$ObjBody = [pscustomobject]@{
Expand Down
2 changes: 1 addition & 1 deletion Modules/CIPPCore/Public/Set-CIPPDefaultAPEnrollment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Set-CIPPDefaultAPEnrollment {
$APIName = 'Add Default Enrollment Status Page'
)

$User = $request.headers.'x-ms-client-principal-name'
$User = $request.headers.'x-ms-client-principal'

try {
$ObjBody = [pscustomobject]@{
Expand Down
2 changes: 1 addition & 1 deletion Modules/CIPPCore/Public/Set-CIPPMailboxArchive.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function Set-CIPPMailboxArchive {
[bool]$ArchiveEnabled
)

$User = $request.headers.'x-ms-client-principal-name'
$User = $request.headers.'x-ms-client-principal'

Try {
if (!$username) { $username = $userid }
Expand Down
2 changes: 1 addition & 1 deletion Modules/CIPPCore/Public/Test-CIPPAccessPermissions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Test-CIPPAccessPermissions {
$ExecutingUser
)

$User = $request.headers.'x-ms-client-principal-name'
$User = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $User -API $APINAME -message 'Started permissions check' -Sev 'Debug'
$Messages = [System.Collections.Generic.List[string]]::new()
$ErrorMessages = [System.Collections.Generic.List[string]]::new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ function Invoke-NinjaOneTenantSync {
},
@{
Name = 'View Devices in CIPP'
Link = "https://$($CIPPURL)/endpoint/reports/devices?customerId=$($Customer.defaultDomainName)"
Link = "https://$($CIPPURL)/endpoint/MEM/devices?customerId=$($Customer.defaultDomainName)"
Icon = 'far fa-eye'
}
)
Expand Down Expand Up @@ -1785,7 +1785,7 @@ function Invoke-NinjaOneTenantSync {
},
@{
Name = 'List Devices'
Link = "https://$CIPPUrl/endpoint/reports/devices?customerId=$($Customer.customerId)"
Link = "https://$CIPPUrl/endpoint/MEM/devices?customerId=$($Customer.customerId)"
Icon = 'fas fa-laptop'
},
@{
Expand Down Expand Up @@ -1963,7 +1963,7 @@ function Invoke-NinjaOneTenantSync {

# Create the Devices Card

$TitleLink = "https://$CIPPUrl/endpoint/reports/devices?customerId=$($Customer.customerId)"
$TitleLink = "https://$CIPPUrl/endpoint/MEM/devices?customerId=$($Customer.customerId)"

$DeviceCardBodyHTML = $DeviceComplianceChartHTML + $DeviceOsChartHTML + $DeviceOnlineChartHTML

Expand Down Expand Up @@ -2175,7 +2175,7 @@ function Invoke-NinjaOneTenantSync {
Value = ($Devices | Measure-Object).count
Description = 'Devices'
Colour = '#CCCCCC'
Link = "https://$CIPPUrl/endpoint/reports/devices?customerId=$($Customer.customerId)"
Link = "https://$CIPPUrl/endpoint/MEM/devices?customerId=$($Customer.customerId)"
})

# Groups
Expand Down

0 comments on commit 3ceac19

Please sign in to comment.