尊敬的客户,您好!
感谢您在 Q&A 论坛上发帖。
要通过命令的方式在 Active Directory (AD) 域环境中删除所有 Windows Server 2012 R2(含)以前版本的计算机账户,可以使用 PowerShell 脚本。
以下是一个示例脚本,您可以在测试环境中运行试试:
# Import Active Directory module
Import-Module ActiveDirectory
# Define the list of OS versions to consider as outdated
$outdatedOS = @(
"Windows Server 2012R2",
"Windows Server 2012",
"Windows Server 2008R2",
"Windows Server 2008",
"Windows Server 2003"
)
# Find and remove outdated OS computer accounts
foreach ($os in $outdatedOS) { Get-ADComputer -Filter "OperatingSystem -like '$os'" -Property OperatingSystem | ForEach-Object { Remove-ADComputer -Identity $_ -Confirm:$false Write-Host "Removed computer account: $($_.Name)"
} }
请在运行此脚本之前确保:
1.您有足够的权限删除计算机账户。
2.对于生产环境,建议先备份数据并在测试环境或非高峰时段执行。
关于“运行过时 OS 的计算机”中的 OS 定义,通常“过时的操作系统”是指微软已经终止支持和更新的操作系统版本。对于 Windows Server 系列,Windows Server 2012 R2 和更早版本都已经进入延长支持或结束支持阶段,因此被认为是“过时的”。具体定义可能会依据你所在组织的政策有所不同。
我希望以上信息对您有所帮助。
如果您有任何问题或疑虑,请随时告诉我们。
Best Regards,
Daisy Zhou
============================================
如果答案有帮助,请点击“接受答案”并投赞成票。