【问题标题】:Changing multiple users passwords in active directory at once一次更改活动目录中的多个用户密码
【发布时间】:2017-02-15 14:45:36
【问题描述】:

是否可以一次更改多个用户的活动目录密码?我可以制作一个用户名列表并像下面这样一次给他们所有相同的密码吗?或者这样的事情是不可能的?

<cfset usernames = 'Sta1, Sta2, Sta3, Sta4, Sta5'>
<cfset password = 'newpassword17!'>

<cfloop list="#usernames#" index="username">
<cfexecute
    name="c:\windows\system32\cmd.exe"
    arguments="/c net user #username# #password# /domain"
    outputfile="C:\Users\administrator\Desktop\test.txt"
    timeout="90">
</cfexecute>
</cfloop>

【问题讨论】:

  • 将 cfexecute 放入名称列表的循环中。
  • @DanBracuk 喜欢这样吗? (上)
  • 理论上看起来不错。当你尝试它时发生了什么?糟糕,逗号后面的空格必须去掉。
  • 没有权限,不幸的是,我仍在尝试找出那部分:(。仅当我在服务器上的命令提示符stackoverflow.com/questions/42234407/… 上时有效
  • 我知道 OP 正在使用 ColdFusion(我也经常使用),但这个任务作为 PowerShell 脚本可能会更好。

标签: powershell cmd coldfusion


【解决方案1】:

OP 正在研究 ColdFusion 解决方案,但确实在 cmets 中请求了这个 PowerShell 示例。所以,请不要给出负面评价,因为这与 OP 请求不符。

@DavidBrierton,请将 PowerShell 标记添加到您的问题中,以便其他人可以找到此答案。

请注意,此 PowerShell 脚本适用于 PowerShell 的现代实现。我在 PowerShell 5.1 上对其进行了测试,但它可能适用于旧版本的 PowerShell。如果您使用的是较旧的 Windows Server,则可能需要调整“安装 RSAT-AD-PowerShell 功能”行。如果需要,我提供了从 Windows 7 到 Windows 2012 R2 的安装说明的 URL。

另一个注意事项:PowerShell 升级是免费的,您可以通过在此处获取软件升级到 5.1 版:https://www.microsoft.com/en-us/download/details.aspx?id=54616

此示例中的第一行代码将显示您安装的 PowerShell 版本。

#display your version of PowerShell
$PSVersionTable.PSVersion

#install the RSAT-AD-PowerShell feature on Windows Server 2012 R2
#Source: https://4sysops.com/archives/how-to-install-the-powershell-active-directory-module/
Add-WindowsFeature RSAT-AD-PowerShell

# create array of usernames
$arrUserNames = @("Sta1", "Sta2", "Sta3", "Sta4", "Sta5")

# assign variable with new password
$password = "newpassword17!"

# loop over usernames and assign a new password
($arrUserNames).split(" ",[StringSplitOptions]'RemoveEmptyEntries') | foreach {
    Write-Host "Changing password for: $_"
    Set-ADAccountPassword -Identity $_ -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $password -Force)
}

【讨论】:

  • 编程语言的相关性不如缺少权限。
  • 是的,根本问题在于权限(我确实提供了如何解决该问题的链接),但您必须问... ColdFusion App Server 是否应该拥有那么多安全权限?如果 ColdFusion 被黑客入侵(或内部滥用),您不是为进一步的滥用/利用打开了大门吗? Microsoft PowerShell 已被开发用于自动执行这些类型的任务。可以使用带有 xp_cmdshell 的 SQL Server 开发此任务。它会起作用吗?是的。好主意?可能不会。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多