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

Azure Runbook使用Set-CsUserCallingSettings报错“流已被消耗”

问题描述
  • 环境:使用Azure Runbook + PowerShell 5.1管理Teams用户呼叫转移状态(PowerShell 7.1预览版会触发权限误报);Azure应用已配置所需Graph API权限,且被授予Teams管理员角色。
  • 正常操作:Runbook内导入模块、获取身份令牌、连接Microsoft Teams、执行Get-CsOnlineUser命令均正常完成。
  • 异常触发:执行Set-CsUserCallingSettings或Get-CsUserCallingSettings命令时,抛出错误:

The stream was already consumed. It cannot be read again

原因分析

经确认,Azure Runbook环境不支持Set-CsUserCallingSettings和Get-CsUserCallingSettings这两个Teams PowerShell cmdlet,此为错误产生的根本原因。

替代解决方案

由于已配置好Graph API权限,可直接通过Microsoft Graph API操作用户呼叫设置,替代上述不兼容的cmdlet。以下是PowerShell示例代码(需使用已获取的Graph访问令牌):

获取用户呼叫转移配置

$userId = "目标用户的UPN或ID"
$graphEndpoint = "https://graph.microsoft.com/v1.0/users/$userId/callingSettings/forwardingConfiguration"
$requestHeaders = @{
    "Authorization" = "Bearer $yourGraphAccessToken"
    "Content-Type"  = "application/json"
}

$currentForwardingSettings = Invoke-RestMethod -Uri $graphEndpoint -Headers $requestHeaders -Method Get

设置用户呼叫转移

$forwardingConfig = @{
    forwardingType      = "immediate" # 可选值:immediate、simultaneous、unanswered、disabled
    targets             = @(
        @{
            id   = "转移目标的UPN或ID"
            type = "user" # 可选值:user、voicemail、externalNumber
        }
    )
    isForwardingEnabled = $true
} | ConvertTo-Json -Depth 3

Invoke-RestMethod -Uri $graphEndpoint -Headers $requestHeaders -Method Put -Body $forwardingConfig

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 20:25:19