From b8167384f04796879aaf5429d35b5210041c569b Mon Sep 17 00:00:00 2001 From: Ka1Nn <58510646+Ka1Nn@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:49:00 +0200 Subject: [PATCH] Update Invoke-IntuneGraphRequest.ps1 Invoke-IntuneGraphRequest -APIVersion "v1.0" -Route "" -Resource "groups" -Method "GET" or Invoke-IntuneGraphRequest -APIVersion "v1.0" -Route "groups" -Resource "" -Method "GET" returns an error : Invoke-IntuneGraphRequest : Cannot validate argument on parameter 'Route'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:124 char:53 + Invoke-IntuneGraphRequest -APIVersion "v1.0" -Route "" -Resource "gro ... + ~~ + CategoryInfo : InvalidData: (:) [Invoke-IntuneGraphRequest], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Invoke-IntuneGraphRequest --- Private/Invoke-IntuneGraphRequest.ps1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Private/Invoke-IntuneGraphRequest.ps1 b/Private/Invoke-IntuneGraphRequest.ps1 index e720bcb..2274bd8 100644 --- a/Private/Invoke-IntuneGraphRequest.ps1 +++ b/Private/Invoke-IntuneGraphRequest.ps1 @@ -19,6 +19,7 @@ function Invoke-IntuneGraphRequest { 1.0.3 - (2022-10-02) Changed content type for requests to support UTF8 1.0.4 - (2023-01-23) Added non-mandatory Route parameter to support different routes of Graph API in addition to better handle error response body depending on PSEdition 1.0.5 - (2023-02-03) Improved error handling + 1.0.6 - (2024-08-22) Enhanced URI construction to handle optional Route parameters #> param( [parameter(Mandatory = $true)] @@ -27,7 +28,6 @@ function Invoke-IntuneGraphRequest { [string]$APIVersion, [parameter(Mandatory = $false)] - [ValidateNotNullOrEmpty()] [string]$Route = "deviceAppManagement", [parameter(Mandatory = $true)] @@ -49,7 +49,11 @@ function Invoke-IntuneGraphRequest { ) try { # Construct full URI - $GraphURI = "https://graph.microsoft.com/$($APIVersion)/$($Route)/$($Resource)" + $GraphURI = if ([string]::IsNullOrEmpty($Route)) { + "https://graph.microsoft.com/$($APIVersion)/$($Resource)" + } else { + "https://graph.microsoft.com/$($APIVersion)/$($Route)/$($Resource)" + } Write-Verbose -Message "$($Method) $($GraphURI)" # Call Graph API and get JSON response @@ -120,4 +124,4 @@ function Invoke-IntuneGraphRequest { } } } -} \ No newline at end of file +}