I wrote a script a while back that gets the the UserPrincipalName, DisplayName, LastLogonTime, CreationTime, Inactive Days, MailboxType, AssignedLicenses, ItemCount, MB Size, and Roles from MSOnline and Exchange Online. It works fine on one server and my laptop but it fails with the message below. The server that I run it from is being decommissioned so I need to move it to a new server. Why would the script work on a server and my laptop but nowhere else?
PS>TerminatingError(Invoke-WebRequest): "{"error":{"code":"BadRequest","message":"Invalid Operation","innererror":{"message":"Invalid Operation","type":"Microsoft.Exchange.Admin.OData.Core.ODataServiceException","stacktrace":" at Microsoft.Exchange.AdminApi.CommandInvocation.CommandInvocation.InvokeCommand(QueryContext queryContext, CmdletInvokeInputType cmdletInvokeInputType)\r\n at Microsoft.Exchange.Admin.OData.Core.PathSegmentToExpressionTranslator.Translate(OperationImportSegment segment)\r\n at Microsoft.Exchange.Admin.OData.Core.QueryContext.ResolveQuery(ODataContext context, Int32 level)\r\n at Microsoft.Exchange.Admin.OData.Core.Handlers.OperationHandler.Process(IODataRequestMessage requestMessage, IODataResponseMessage responseMessage)\r\n at Microsoft.Exchange.Admin.OData.Core.Handlers.RequestHandler.Process(Stream requestStream)","internalexception":{"message":"Expired or Invalid pagination request. Default Expiry time is 00:30:00","type":"System.Exception","stacktrace":""}}}}"
Write-ErrorMessage : Expired or Invalid pagination request. Default Expiry time is 00:30:00
At C:\Users\Me\AppData\Local\Temp\tmpEXO_3gsqzody.faf\tmpEXO_3gsqzody.faf.psm1:1107 char:13
+ Write-ErrorMessage $ErrorObject $IsFromBatchingRequest
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Mailbox], Exception
+ FullyQualifiedErrorId : [Server=DM6PR14MB4156,RequestId=ebb50db0-607b-668c-4603-4639ca0ba4c1,TimeStamp=Wed, 21
Sep 2022 18:52:31 GMT],Write-ErrorMessage
Write-ErrorMessage : Expired or Invalid pagination request. Default Expiry time is 00:30:00
At C:\Users\Me\AppData\Local\Temp\tmpEXO_3gsqzody.faf\tmpEXO_3gsqzody.faf.psm1:1107 char:13
+ Write-ErrorMessage $ErrorObject $IsFromBatchingRequest
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Mailbox], Exception
+ FullyQualifiedErrorId : [Server=DM6PR14MB4156,RequestId=ebb50db0-607b-668c-4603-4639ca0ba4c1,TimeStamp=Wed, 21 Sep 2022 18:52:31 GMT],Write-Erro
rMessage