【问题标题】:Powershell script to deactivate the Windows users (from CSV file) in Windows Server 2003用于在 Windows Server 2003 中停用 Windows 用户(来自 CSV 文件)的 Powershell 脚本
【发布时间】:2017-04-21 21:56:47
【问题描述】:

是否有任何 powershell 脚本可以在 Windows Server 2003 中停用 Windows 用户(来自 CSV 文件)?这些 Windows 用户是本地用户帐户(不是 AD 帐户)。事实上,我发现了很多这样的 AD 脚本。非常感谢您的建议。

【问题讨论】:

    标签: windows powershell csv active-directory


    【解决方案1】:

    这应该对您有所帮助。请根据您的要求更改占位符:

    $EnableUser = 512 
    $DisableUser = 2 
    $PasswordNotExpire = 65536 # password never expires
    $PasswordCantChange = 64  # passwords cannot be changed
    $users = Import-Csv "path\Users_to_disable.csv" # I believe you have only single column else you have to pick the column 
    $computer = $env:COMPUTERNAME
    
    Foreach($user in $users){ $user = [ADSI]"WinNT://$computer/$user"
    $user.userflags = $DisableUser+$PasswordNotExpire+$PasswordCantChange
    #$user.Userflags = $EnableUser+$PasswordNotExpire+$PasswordCantChange
    $user.setinfo()
    }
    

    【讨论】:

    • 谢谢@Ranadip!让我试试看。
    • @KyawThurein :如果对您有帮助,请接受答案。
    • +1 @Ranadip。在 [ADSI]"WinNT://$computer/$user" 之前添加 $user = $user.{csv_column_name} 可以解决问题!谢谢
    • 太棒了。很高兴为您提供指导:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多