You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When handling the HTTP response (200 OK) an exception is thrown when using the Search-MgDrive Cmdlet. No issue with Graph Explorer.
CmdletException: InvalidCastException - Unable to cast object of type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'
Example usage of Cmdlet:
Search-MgDrive-DriveId $DriveId-Q "Sample Text"
Heavily redacted debug log of Cmdlet use.:
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletProcessRecordAsyncStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: https://graph.microsoft.com/v1.0/drives/REDACTEDDRIVEID/microsoft.graph.search(q='Sample Text')
DEBUG: RequestCreated: https://graph.microsoft.com/v1.0/drives/REDACTEDDRIVEID/microsoft.graph.search(q='Sample Text')
DEBUG: HeaderParametersAdded: https://graph.microsoft.com/v1.0/drives/REDACTEDDRIVEID/microsoft.graph.search(q='Sample Text')
DEBUG: GET /v1.0/drives/REDACTEDDRIVEID/microsoft.graph.search(q='Sample%20Text') HTTP/1.1
HTTP: graph.microsoft.com
DEBUG: BeforeCall:
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
DEBUG: GET https://graph.microsoft.com/v1.0/drives/REDACTEDDRIVEID/microsoft.graph.search(q='Sample%20Text')
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
request-id: 00000000-0000-0000-0000-000000000000
client-request-id: 00000000-0000-0000-0000-000000000000
x-ms-ags-diagnostic: REDACTED
X-SearchPlatform: Substrate,Substrate
OData-Version: 4.0
Cache-Control: no-cache
Date: Fri, 10 Sep 2021 04:06:06 GMT
Content-Encoding: gzip
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)","value":[{"@odata.type":"#microsoft.graph.driveItem","createdDateTime":"2020-01-01T00:00:00Z","id":"0000000000000000000000000000000000","lastModifiedDateTime":"2020-01-01T00:00:00Z","name":"Example.pdf","webUrl":"https://redacted-my.sharepoint.com/personal/user_example_com/Documents/Example.pdf","size":250000,"createdBy":{"user":{"email":"[email protected]","displayName":"User"}},"lastModifiedBy":{"user":{"email":"[email protected]","displayName":"User"}},"parentReference":{"driveId":"REDACTEDDRIVEID","driveType":"business","id":"0000000000000000000000000000000000"},"file":{"mimeType":"application/pdf"},"fileSystemInfo":{"createdDateTime":"2020-01-01T00:00:00Z","lastModifiedDateTime":"2020-01-01T00:00:00Z"},"searchResult":{},"shared":{"scope":"users"}}]}
DEBUG: Finally:
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletException: InvalidCastException - Unable to cast object of type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'. : at Microsoft.Graph.PowerShell.Files.<>c.<DrivesSearch1_Call>b__789_0(Task`1 body)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Cmdlets.SearchMgDrive_Search1.<onOk>d__57.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Files.<DrivesSearch1_Call>d__789.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Graph.PowerShell.Files.<DrivesSearch1_Call>d__789.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Files.<DrivesSearch1>d__787.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Cmdlets.SearchMgDrive_Search1.<ProcessRecordAsync>d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Graph.PowerShell.Cmdlets.SearchMgDrive_Search1.<ProcessRecordAsync>d__53.MoveNext()
Search-MgDrive : Unable to cast object of type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'.
At line:1 char:1
+ Search-MgDrive -DriveId $DriveId -Q "Sample Text"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Search-MgDrive_Search1], InvalidCastException
+ FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.SearchMgDrive_Search1
DEBUG: CmdletProcessRecordEnd:
DEBUG: CmdletEndProcessing:
The text was updated successfully, but these errors were encountered:
$Response=Invoke-MgGraphRequest-Method GET -Uri "https://graph.microsoft.com/v1.0/drives/$($DriveId)/root/search(q='Sample Text')"$Response.value|ForEach-Object { Write-Host"$($_.name) [$($_.id)] by $($_.createdBy.user.email) at $($_.webUrl)" }
Seems like Microsoft Graph has it's own undocumented endpoint of .../microsoft.graph.search instead of .../root/search.
Thanks for opening the issue. This is an issue with the OpenAPI document that the SDK is generated from and is being tracked here. Our recommendation is for customers to use Invoke-MgGraphRequest as shown above.
Uh oh!
There was an error while loading. Please reload this page.
When handling the HTTP response (200 OK) an exception is thrown when using the
Search-MgDrive
Cmdlet. No issue with Graph Explorer.CmdletException: InvalidCastException - Unable to cast object of type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'
Example usage of Cmdlet:
Heavily redacted debug log of Cmdlet use.:
The text was updated successfully, but these errors were encountered: