You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AzureAD PowerShell模块时持续出现Newtonsoft.Json.JsonReaderException错误

解决AzureAD PowerShell模块JSON读取错误问题

问题现象

运行AzureAD模块任意命令均触发JSON读取错误,示例命令:

New-AzureADServiceAppRoleAssignment -Id "any id" -ResourceId "any id" -ObjectId "any id" -PrincipalID "any id"

错误输出:

Error reading JToken from JsonReader. Path '', line 0, position 0
At line:1 char:1
New-AzureADServiceAppRoleAssignment -Id ....
CategoryInfo : NotSpecified: (:) [New-AzureADServiceAppRoleAssignment], JsonReaderException
FullyQualifiedErrorId: Newtonsoft.Json.JsonReaderException.Microsoft.Open.AzureAD16.Powershell.NewServicePrincipalAppRoleAssignment.

解决步骤

  • 卸载并重装AzureAD模块
    先清理现有模块:

    Uninstall-Module -Name AzureAD -Force
    Uninstall-Module -Name AzureADPreview -Force # 若安装了预览版一并卸载
    

    重新安装稳定版:

    Install-Module -Name AzureAD -Force -AllowClobber
    
  • 修复Newtonsoft.Json依赖
    若模块重装后问题依旧:

    1. 打开AzureAD模块默认安装目录:C:\Program Files\WindowsPowerShell\Modules\AzureAD
    2. 进入对应版本的文件夹,检查lib目录下是否存在Newtonsoft.Json.dll
    3. 若文件缺失或损坏,下载模块依赖的10.x版本Newtonsoft.Json包,将Newtonsoft.Json.dll复制到该lib目录
  • 清理PowerShell缓存并重启

    Remove-Module AzureAD -Force
    $env:PSModuleCache = ""
    

    重启PowerShell后重新导入模块:

    Import-Module AzureAD
    
  • 检查PowerShell版本兼容性
    AzureAD模块对PowerShell 7支持有限,建议切换到PowerShell 5.1环境重试。

内容的提问来源于stack exchange,提问作者user20826116

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 18:55:33