清理AD用户

时间:2017-10-16 18:29:14

标签: powershell active-directory

我试图在我的环境中自动化更多。现在我有以下脚本将csv文件与AD进行比较,并导出需要创建的新用户列表。我想扩展这个并禁用在AD中找到的任何用户而不是csv。

非常感谢任何帮助。

$results = @()
$results = ForEach ($User in (Import-Csv c:\scripts\adusers.csv)) {
$userName = $User.ID
$sch = $User.DEPT
$first = $User.FN
$last = $user.LN
$pass = $User.BDATE
$yog = $User.GRD
[PSCustomObject]@{
    Username = $userName
    School = $sch
    First = $first
    Last = $last
    Password = $pass
    YOG = $yog
    Found = [boolean]((Get-ADUser -filter {samaccountname -eq $userName}) -ne $null)
    }
}
$results | where {-not $_.found} | Select Username,School,First,Last,Password,YOG | 
   Export-Csv c:\Scripts\newusers.csv -NoTypeInformation

0 个答案:

没有答案