执行GetMsolUser时,“在对象图中可以序列化或反序列化的项目的最大数量” – 全部

我有一个办公室365租户,我执行以下命令

Get-MsolUser -All 

在服务器AI上得到

 get-msoluser : The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://provisioning.microsoftonline.com/:ListUsersResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details. At line:1 char:1 + get-msoluser -All + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [Get-MsolUser], NetDispatcherFaultException + FullyQualifiedErrorId : System.ServiceModel.Dispatcher.NetDispatcherFaultException,Microsoft.Online.Administrati on.Automation.GetUser 

在服务器b上与同一个租户交谈,它工作正常。 两者都具有相同版本的azure活动目录powershell命令行开关。

从谷歌search我看到你可以将MaxItemsInObjectGraph设置为一个更高的值,但我不知道在哪里可以find适当的configuration文件来做到这一点的PowerShell。 甚至是什么改变导致这个问题,服务器也工作得很好。

 <dataContractSerializer maxItemsInObjectGraph="2147483646" /> 

到你的machine.config
C:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Config中
或更旧的.NET在:
C:\ WINDOWS \ Microsoft.NET \ Framework64 \ V2.0.50727 \ CONFIG

(使用64位的framework64文件夹,否则使用框架文件夹)

文本必须添加到endpointBehaviours元素中。 所以我看起来像这样:

 <endpointBehaviors> <dataContractSerializer maxItemsInObjectGraph="2147483646" /> <Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior/> </endpointBehaviors> 

对于那些使用未修改的machine.config文件的人来说,这是一个更完整的答案。

1)用$ psversiontable.psversion.tostring()检查你的powershell版本

2)移动到与您的PowerShell版本C:\ Windows \ Microsoft.NET \ Framework * \ * \ CONFIG相对应的文件夹

3)修改machine.config。

在以下几行之间:

 </configSections> <configProtectedData defaultProvider="RsaProtectedConfigurationProvider"> 

加:

 <system.serviceModel> <commonBehaviors> <endpointBehaviors> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </endpointBehaviors> </commonBehaviors> </system.serviceModel>