Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Graph API Calls to be Dynamic Cloud Endpoint not hard-coded .com #5236

Open
wants to merge 3 commits into
base: Dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* M365DSCDRGUtil
* Fixes an issue where non-unique properties were not combined
properly with their respective parent setting.
* Fixed refrences to graph.microsoft.com with dynamic domain name based on target cloud
* Impacted AADAdminConsentRequestPolicy, AADApplication, AADConditionalAccessPolicy, AADGroup, AADNamedLocationPolicy, AADServiePrincipal, IntuneASRRulesPolicyWindows10, IntuneAccountProtectionLocalUsersGroupMembershipPolicy, IntuneAccountProtectionPolicy,IntuneAppProtectionPolicyiOS,IntuneDeviceConfigurationAdministrativeTemplatePolicyWindows10,IntuneDeviceConfigurationSCEPCertificatePolicyWindows10, IntuneDeviceConfigurationWiredNetworkPolicyWindows10,IntuneDeviceEnrollmentStatusPageWindows10, IntuneDiskEncryptionMacOS, IntunePolicySets, IntuneSettingCatalogCustomPolicyWindows10, M365DSCRGUtil
* DEPENDENCIES
* Updated ExchangeOnlineManagement to version 3.6.0.
* Updated Microsoft.Graph to version 2.24.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ function Set-TargetResource

$updateJSON = ConvertTo-Json $updateParameters
Write-Verbose -Message "Updating the Entra Id Admin Consent Request Policy with values: $updateJSON"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + 'beta/policies/adminConsentRequestPolicy'
Invoke-MgGraphRequest -Method 'PUT' `
-Uri 'https://graph.microsoft.com/beta/policies/adminConsentRequestPolicy' `
-Uri $Uri `
-Body $updateJSON | Out-Null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,9 @@ function Get-TargetResource

try
{
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/applications/$($AADBetaApp.Id)/onPremisesPublishing"
$oppInfo = Invoke-MgGraphRequest -Method GET `
-Uri "https://graph.microsoft.com/beta/applications/$($AADBetaApp.Id)/onPremisesPublishing" `
-Uri $Uri `
-ErrorAction SilentlyContinue
}
catch
Expand Down Expand Up @@ -1135,8 +1136,10 @@ function Set-TargetResource
$onPremisesPublishingValue.Add('singleSignOnSettings', $singleSignOnValues)
$onPremisesPayload = ConvertTo-Json $onPremisesPublishingValue -Depth 10 -Compress
Write-Verbose -Message "Updating the OnPremisesPublishing settings for application {$($currentAADApp.DisplayName)} with payload: $onPremisesPayload"

$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/applications/$($currentAADApp.Id)/onPremisesPublishing"
Invoke-MgGraphRequest -Method 'PATCH' `
-Uri "https://graph.microsoft.com/beta/applications/$($currentAADApp.Id)/onPremisesPublishing" `
-Uri $Uri `
-Body $onPremisesPayload
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,9 @@ function Set-TargetResource
try
{
Write-Verbose -Message "Updating existing policy with values: $(Convert-M365DscHashtableToString -Hashtable $NewParameters)"
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($currentPolicy.Id)" -Body $NewParameters

$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/identity/conditionalAccess/policies/$($currentPolicy.Id)"
Invoke-MgGraphRequest -Method PATCH -Uri $Uri -Body $NewParameters
}
catch
{
Expand All @@ -1691,7 +1693,8 @@ function Set-TargetResource
{
try
{
Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/policies' -Body $NewParameters
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/identity/conditionalAccess/policies"
Invoke-MgGraphRequest -Method POST -Uri $Uri -Body $NewParameters
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ function Get-TargetResource

# Licenses
$assignedLicensesValues = $null
$uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "v1.0/groups/$($Group.Id)/assignedLicenses"

$assignedLicensesRequest = Invoke-MgGraphRequest -Method 'GET' `
-Uri "https://graph.microsoft.com/v1.0/groups/$($Group.Id)/assignedLicenses"
-Uri $uri

if ($assignedLicensesRequest.value.Length -gt 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function Set-TargetResource
Write-Verbose -Message "Creating New AAD Named Location {$Displayname)} with attributes: $VerboseAttributes"
$JSONValue = ConvertTo-Json $desiredValues | Out-String
Write-Verbose -Message "JSON: $JSONValue"
$APIUrl = 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations'
$APIUrl = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "v1.0/identity/conditionalAccess/namedLocations"
Invoke-MgGraphRequest -Method POST `
-Uri $APIUrl `
-Body $JSONValue | Out-Null
Expand All @@ -308,7 +308,7 @@ function Set-TargetResource
Write-Verbose -Message "Updating AAD Named Location {$Displayname)} with attributes: $VerboseAttributes"
$JSONValue = ConvertTo-Json $desiredValues | Out-String
Write-Verbose -Message "JSON: $JSONValue"
$APIUrl = "https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations/$($currentAADNamedLocation.Id)"
$APIUrl = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "v1.0/identity/conditionalAccess/namedLocations/$($currentAADNamedLocation.Id)"
Invoke-MgGraphRequest -Method PATCH `
-Uri $APIUrl `
-Body $JSONValue | Out-Null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ function Get-TargetResource
}

[Array]$complexDelegatedPermissionClassifications = @()
$permissionClassifications = Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/servicePrincipals(appId='$AppId')/delegatedPermissionClassifications" -Method Get
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "v1.0/servicePrincipals(appId='$AppId')/delegatedPermissionClassifications"
$permissionClassifications = Invoke-MgGraphRequest -Uri $Uri -Method Get
foreach ($permissionClassification in $permissionClassifications.Value){
$hashtable = @{
classification = $permissionClassification.Classification
Expand Down Expand Up @@ -448,7 +449,8 @@ function Set-TargetResource
classification = $permissionClassification.Classification
permissionName = $permissionClassification.permissionName
}
Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/servicePrincipals(appId='$($currentParameters.AppId)')/delegatedPermissionClassifications" -Method Post -Body $params
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "v1.0/servicePrincipals(appId='$($currentParameters.AppId)')/delegatedPermissionClassifications"
Invoke-MgGraphRequest -Uri $Uri -Method Post -Body $params
}
}
}
Expand Down Expand Up @@ -585,9 +587,10 @@ function Set-TargetResource
if ($null -ne $DelegatedPermissionClassifications)
{
# removing old perm classifications
$permissionClassificationList = Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/servicePrincipals(appId='$($currentParameters.AppId)')/delegatedPermissionClassifications" -Method Get
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "v1.0/servicePrincipals(appId='$($currentParameters.AppId)')/delegatedPermissionClassifications"
$permissionClassificationList = Invoke-MgGraphRequest -Uri $Uri -Method Get
foreach($permissionClassification in $permissionClassificationList.Value){
Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/servicePrincipals(appId='$($currentParameters.AppId)')/delegatedPermissionClassifications/$($permissionClassification.Id)" -Method Delete
Invoke-MgGraphRequest -Uri "$($Uri)/$($permissionClassification.Id)" -Method Delete
}

# adding new perm classifications
Expand All @@ -596,7 +599,7 @@ function Set-TargetResource
classification = $permissionClassification.Classification
permissionName = $permissionClassification.permissionName
}
Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/servicePrincipals(appId='$($currentParameters.AppId)')/delegatedPermissionClassifications" -Method Post -Body $params
Invoke-MgGraphRequest -Uri $Uri -Method Post -Body $params
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ function Set-TargetResource
#Update-MgBetaDeviceManagementIntent does not support updating the property settings
#Update-MgBetaDeviceManagementIntentSetting only support updating a single setting at a time
#Using Rest to reduce the number of calls
$Uri = "https://graph.microsoft.com/beta/deviceManagement/intents/$($currentPolicy.Identity)/updateSettings"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/intents/$($currentPolicy.Identity)/updateSettings"
$body = @{'settings' = $settings }
Invoke-MgGraphRequest -Method POST -Uri $Uri -Body ($body | ConvertTo-Json -Depth 20) -ContentType 'application/json' 4> $null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ function Update-DeviceManagementConfigurationPolicy
$templateReference = @{
'templateId' = $TemplateReferenceId
}

$Uri = "https://graph.microsoft.com/beta/deviceManagement/ConfigurationPolicies/$DeviceManagementConfigurationPolicyId"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/ConfigurationPolicies/$DeviceManagementConfigurationPolicyId"
$policy = @{
'name' = $DisplayName
'description' = $Description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ function Set-TargetResource
#Update-MgBetaDeviceManagementIntent does not support updating the property settings
#Update-MgBetaDeviceManagementIntentSetting only support updating a single setting at a time
#Using Rest to reduce the number of calls
$Uri = "https://graph.microsoft.com/beta/deviceManagement/intents/$($currentPolicy.Identity)/updateSettings"

$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/intents/$($currentPolicy.Identity)/updateSettings"
$body = @{'settings' = $settings }
Invoke-MgGraphRequest -Method POST -Uri $Uri -Body ($body | ConvertTo-Json -Depth 20) -ContentType 'application/json' 4> $null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ function Get-IntuneAppProtectionPolicyiOSAssignment

try
{
$Url = "https://graph.microsoft.com/beta/deviceAppManagement/iosManagedAppProtections('$IosManagedAppProtectionId')/assignments"
$Url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceAppManagement/iosManagedAppProtections('$IosManagedAppProtectionId')/assignments"
$response = Invoke-MgGraphRequest -Method Get `
-Uri $Url
return $response.value
Expand Down Expand Up @@ -1333,7 +1333,7 @@ function Update-IntuneAppProtectionPolicyiOSAssignment
)
try
{
$Url = "https://graph.microsoft.com/beta/deviceAppManagement/iosManagedAppProtections('$IosManagedAppProtectionId')/assign"
$Url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceAppManagement/iosManagedAppProtections('$IosManagedAppProtectionId')/assign"
# Write-Verbose -Message "Group Assignment for iOS App Protection policy with JSON payload: `r`n$JSONContent"
Invoke-MgGraphRequest -Method POST `
-Uri $Url `
Expand Down Expand Up @@ -1366,7 +1366,7 @@ function Update-IntuneAppProtectionPolicyiOSApp

try
{
$Url = "https://graph.microsoft.com/beta/deviceAppManagement/iosManagedAppProtections('$IosManagedAppProtectionId')/targetApps"
$Url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceAppManagement/iosManagedAppProtections('$IosManagedAppProtectionId')/targetApps"
# Write-Verbose -Message "Group Assignment for iOS App Protection policy with JSON payload: `r`n$JSONContent"
Invoke-MgGraphRequest -Method POST `
-Uri $Url `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ function Update-DeviceConfigurationGroupPolicyDefinitionValue
)
try
{
$Uri = "https://graph.microsoft.com/beta/deviceManagement/groupPolicyConfigurations/$DeviceConfigurationPolicyId/updateDefinitionValues"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/groupPolicyConfigurations/$DeviceConfigurationPolicyId/updateDefinitionValues"

$body = @{}
$DefinitionValueToRemoveIds = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,7 @@ function Get-DeviceConfigurationPolicyRootCertificate
[System.String]
$DeviceConfigurationPolicyId
)

$Uri = " https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windows81SCEPCertificateProfile/rootCertificate"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windows81SCEPCertificateProfile/rootCertificate"
$result = Invoke-MgGraphRequest -Method Get -Uri $Uri -ErrorAction Stop

return $result
Expand All @@ -1031,8 +1030,8 @@ function Update-DeviceConfigurationPolicyRootCertificateId
[System.String]
$RootCertificateId
)

$Uri = " https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windows81SCEPCertificateProfile/rootCertificate/`$ref"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windows81SCEPCertificateProfile/rootCertificate/`$ref"
$ref = @{
'@odata.id' = "https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations('$RootCertificateId')"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,7 @@ function Get-DeviceConfigurationPolicyCertificate
[System.String]
$CertificateName
)

$Uri = "https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windowsWiredNetworkConfiguration/$CertificateName"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windowsWiredNetworkConfiguration/$CertificateName"
try
{
$result = Invoke-MgGraphRequest -Method Get -Uri $Uri 4>$null
Expand Down Expand Up @@ -1228,9 +1227,8 @@ function Update-DeviceConfigurationPolicyCertificateId
[System.String]
$CertificateName
)

$Uri = "https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windowsWiredNetworkConfiguration/$CertificateName/`$ref"

$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windowsWiredNetworkConfiguration/$CertificateName/`$ref"

if ($CertificateName -eq 'rootCertificatesForServerValidation')
{
$method = 'POST'
Expand Down Expand Up @@ -1271,7 +1269,7 @@ function Remove-DeviceConfigurationPolicyCertificateId

foreach ($certificateId in $CertificateIds)
{
$Uri = " https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windowsWiredNetworkConfiguration/$CertificateName/$certificateId/`$ref"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceConfigurations('$DeviceConfigurationPolicyId')/microsoft.graph.windowsWiredNetworkConfiguration/$CertificateName/$certificateId/`$ref"
Invoke-MgGraphRequest -Method DELETE -Uri $Uri -Body ($ref | ConvertTo-Json) -ErrorAction Stop 4>$null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ function Set-TargetResource
$intuneAssignments += ConvertTo-IntunePolicyAssignment -Assignments $Assignments
}
$body = @{'enrollmentConfigurationAssignments' = $intuneAssignments} | ConvertTo-Json -Depth 100
$Uri = "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations/$($policy.Id)/assign"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceEnrollmentConfigurations/$($policy.Id)/assign"
Invoke-MgGraphRequest -Method POST -Uri $Uri -Body $body -ErrorAction Stop

Update-DeviceEnrollmentConfigurationPriority `
Expand Down Expand Up @@ -448,7 +448,7 @@ function Set-TargetResource
$intuneAssignments += ConvertTo-IntunePolicyAssignment -Assignments $Assignments
}
$body = @{'enrollmentConfigurationAssignments' = $intuneAssignments} | ConvertTo-Json -Depth 100
$Uri = "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations/$($currentInstance.Id)/assign"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceEnrollmentConfigurations/$($currentInstance.Id)/assign"
Invoke-MgGraphRequest -Method POST -Uri $Uri -Body $body -ErrorAction Stop

if ($PSBoundParameters.ContainsKey('Priority') -and $Priority -ne $currentInstance.Priority)
Expand Down Expand Up @@ -826,7 +826,7 @@ function Update-DeviceEnrollmentConfigurationPriority
)
try
{
$Uri = "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations/$DeviceEnrollmentConfigurationId/setpriority"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/deviceEnrollmentConfigurations/$DeviceEnrollmentConfigurationId/setpriority"
$body = @{'priority' = $Priority } | ConvertTo-Json -Depth 100
#write-verbose -Message $body
Invoke-MgGraphRequest `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function Set-TargetResource
Update-MgBetaDeviceManagementIntent -DeviceManagementIntentId $currentInstance.Id -BodyParameter $UpdateParameters

#region resource generator code
$Uri = "https://graph.microsoft.com/beta/deviceManagement/intents/$($currentInstance.Id)/updateSettings"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + "beta/deviceManagement/intents/$($currentInstance.Id)/updateSettings"
$body = @{'settings' = $settings }
Invoke-MgGraphRequest -Method POST -Uri $Uri -Body ($body | ConvertTo-Json -Depth 20) -ContentType 'application/json' 4> $null

Expand Down
Loading
Loading