|
| 1 | +function Get-CIPPURLName { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Gets the correct Microsoft Graph URL based on the OData type of a template |
| 5 | + .DESCRIPTION |
| 6 | + This function examines the @odata.type property of a JSON template object and returns |
| 7 | + the appropriate full Microsoft Graph API URL for that resource type. |
| 8 | + .PARAMETER Template |
| 9 | + The template object containing the @odata.type property to analyze |
| 10 | + .FUNCTIONALITY |
| 11 | + Internal |
| 12 | + .EXAMPLE |
| 13 | + Get-CIPPURLName -Template $MyTemplate |
| 14 | + .EXAMPLE |
| 15 | + $Template | Get-CIPPURLName |
| 16 | + #> |
| 17 | + [CmdletBinding()] |
| 18 | + param( |
| 19 | + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] |
| 20 | + [PSCustomObject]$Template |
| 21 | + ) |
| 22 | + |
| 23 | + # Extract the OData type from the template |
| 24 | + $ODataType = $Template.'@odata.type' |
| 25 | + if ($Template.urlName) { return $Template.urlName } |
| 26 | + |
| 27 | + if (-not $ODataType) { |
| 28 | + Write-Warning 'No @odata.type property found in template' |
| 29 | + return $null |
| 30 | + } |
| 31 | + |
| 32 | + # Determine the full Microsoft Graph URL based on the OData type |
| 33 | + $URLName = switch -wildcard ($ODataType) { |
| 34 | + # Device Compliance Policies |
| 35 | + '*CompliancePolicy' { |
| 36 | + 'deviceManagement/deviceCompliancePolicies' |
| 37 | + } |
| 38 | + '*deviceCompliancePolicy' { |
| 39 | + 'deviceManagement/deviceCompliancePolicies' |
| 40 | + } |
| 41 | + |
| 42 | + # Managed App Policies (App Protection) |
| 43 | + '*ManagedAppProtection' { |
| 44 | + 'deviceAppManagement/managedAppPolicies' |
| 45 | + } |
| 46 | + '*managedAppPolicies' { |
| 47 | + 'deviceAppManagement/managedAppPolicies' |
| 48 | + } |
| 49 | + '*managedAppPolicy' { |
| 50 | + 'deviceAppManagement/managedAppPolicies' |
| 51 | + } |
| 52 | + '*appProtectionPolicy' { |
| 53 | + 'deviceAppManagement/managedAppPolicies' |
| 54 | + } |
| 55 | + |
| 56 | + # Configuration Policies (Settings Catalog) |
| 57 | + '*configurationPolicies' { |
| 58 | + 'deviceManagement/configurationPolicies' |
| 59 | + } |
| 60 | + '*deviceManagementConfigurationPolicy' { |
| 61 | + 'deviceManagement/configurationPolicies' |
| 62 | + } |
| 63 | + |
| 64 | + # Windows Driver Update Profiles |
| 65 | + '*windowsDriverUpdateProfiles' { |
| 66 | + 'deviceManagement/windowsDriverUpdateProfiles' |
| 67 | + } |
| 68 | + '*windowsDriverUpdateProfile' { |
| 69 | + 'deviceManagement/windowsDriverUpdateProfiles' |
| 70 | + } |
| 71 | + |
| 72 | + # Device Configurations |
| 73 | + '*deviceConfigurations' { |
| 74 | + 'deviceManagement/deviceConfigurations' |
| 75 | + } |
| 76 | + '*deviceConfiguration' { |
| 77 | + 'deviceManagement/deviceConfigurations' |
| 78 | + } |
| 79 | + |
| 80 | + # Group Policy Configurations (Administrative Templates) |
| 81 | + '*groupPolicyConfigurations' { |
| 82 | + 'deviceManagement/groupPolicyConfigurations' |
| 83 | + } |
| 84 | + '*groupPolicyConfiguration' { |
| 85 | + 'deviceManagement/groupPolicyConfigurations' |
| 86 | + } |
| 87 | + |
| 88 | + # Conditional Access Policies |
| 89 | + '*conditionalAccessPolicy' { |
| 90 | + 'identity/conditionalAccess/policies' |
| 91 | + } |
| 92 | + |
| 93 | + # Device Enrollment Configurations |
| 94 | + '*deviceEnrollmentConfiguration' { |
| 95 | + 'deviceManagement/deviceEnrollmentConfigurations' |
| 96 | + } |
| 97 | + '*enrollmentConfiguration' { |
| 98 | + 'deviceManagement/deviceEnrollmentConfigurations' |
| 99 | + } |
| 100 | + |
| 101 | + # Mobile App Configurations |
| 102 | + '*mobileAppConfiguration' { |
| 103 | + 'deviceAppManagement/mobileAppConfigurations' |
| 104 | + } |
| 105 | + '*appConfiguration' { |
| 106 | + 'deviceAppManagement/mobileAppConfigurations' |
| 107 | + } |
| 108 | + |
| 109 | + # Windows Feature Update Profiles |
| 110 | + '*windowsFeatureUpdateProfile' { |
| 111 | + 'deviceManagement/windowsFeatureUpdateProfiles' |
| 112 | + } |
| 113 | + |
| 114 | + # Device Health Scripts (Remediation Scripts) |
| 115 | + '*deviceHealthScript' { |
| 116 | + 'deviceManagement/deviceHealthScripts' |
| 117 | + } |
| 118 | + |
| 119 | + # Device Management Scripts (PowerShell Scripts) |
| 120 | + '*deviceManagementScript' { |
| 121 | + 'deviceManagement/deviceManagementScripts' |
| 122 | + } |
| 123 | + |
| 124 | + # Mobile Applications |
| 125 | + '*mobileApp' { |
| 126 | + 'deviceAppManagement/mobileApps' |
| 127 | + } |
| 128 | + '*winGetApp' { |
| 129 | + 'deviceAppManagement/mobileApps' |
| 130 | + } |
| 131 | + '*officeSuiteApp' { |
| 132 | + 'deviceAppManagement/mobileApps' |
| 133 | + } |
| 134 | + |
| 135 | + # Named Locations |
| 136 | + '*namedLocation' { |
| 137 | + 'identity/conditionalAccess/namedLocations' |
| 138 | + } |
| 139 | + '*ipNamedLocation' { |
| 140 | + 'identity/conditionalAccess/namedLocations' |
| 141 | + } |
| 142 | + '*countryNamedLocation' { |
| 143 | + 'identity/conditionalAccess/namedLocations' |
| 144 | + } |
| 145 | + |
| 146 | + # Default fallback |
| 147 | + default { |
| 148 | + Write-Warning "Unknown OData type: $ODataType" |
| 149 | + $null |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + return $URLName |
| 154 | +} |
| 155 | + |
0 commit comments