powershell AD-删除用户
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell AD-删除用户相关的知识,希望对你有一定的参考价值。
param ($inputfile='.\Users.csv')
$csv = Import-CSV $inputfile
$log = "C:\temp\ROBCleanup.csv"
## generate log file
Add-Content -Path $log -Value '"User","Email","Path"'
ForEach ($user in $csv)
{
#Write-output $user.Name
$email = [string]$user.Name
try {
$u = Get-aduser -Filter { emailaddress -Like $email} -Properties emailaddress -ErrorAction Stop
if($u){
Write-Output $u.DistinguishedName
## add current information to log file
$NewLine = "{0},{1},{2}" -f $u.name, $u.emailaddress, $u.DistinguishedName
$NewLine | add-content -path $log
}
Remove-ADUser –Identity $u.SamAccountName -ErrorAction Stop
} catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host -ForegroundColor Red $("Error: " + $ErrorMessage)
}
}
以上是关于powershell AD-删除用户的主要内容,如果未能解决你的问题,请参考以下文章