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

如何通过CSV批量设置Azure服务账户的密码永不过期?

批量设置Azure AD服务账户密码永不过期(从CSV导入)

步骤1:准备CSV文件

创建包含目标服务账户的CSV文件,确保包含UserPrincipalName(或ObjectId)列,示例内容:

UserPrincipalName
test01@company.com
test02@company.com
svc-batch-test@company.com

步骤2:完整PowerShell脚本

结合你已有的代码,添加CSV导入和foreach循环实现批量操作,脚本如下:

# 连接Azure AD
Connect-AzureAD -AccountId $env:USERNAME@company.com

# 导入CSV文件,替换为你的实际文件路径
$serviceAccounts = Import-Csv -Path "C:\your-path\service-accounts.csv"

# 遍历账户批量设置密码永不过期
foreach ($account in $serviceAccounts) {
    try {
        # 若CSV用的是ObjectId列,替换为$account.ObjectId
        Set-AzureADUser -ObjectId $account.UserPrincipalName -PasswordPolicies DisablePasswordExpiration
        Write-Host "✅ 成功配置 $($account.UserPrincipalName) 密码永不过期" -ForegroundColor Green
    }
    catch {
        Write-Host "❌ 配置 $($account.UserPrincipalName) 失败: $($_.Exception.Message)" -ForegroundColor Red
    }
}

关键注意事项

  • 确保CSV列名与脚本中引用的字段一致(比如用ObjectId就把$account.UserPrincipalName改成$account.ObjectId)
  • 执行脚本的账户需要拥有Azure AD的用户管理员或全局管理员权限
  • 建议先选取1-2个测试账户验证脚本有效性,再执行批量操作

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 23:35:32