我需要使用导入的csv文件从Active Directory中删除用户 [英] I need to delete users from Active Directory using a imported csv file

查看:127
本文介绍了我需要使用导入的csv文件从Active Directory中删除用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含用户名列表的CSV文件,我需要使用 Remove-ADObject命令从Active Directory中删除所有这些用户。我对该命令的语法不是很熟悉-希望你们能在这里为我提供帮助。

I have a CSV file with a list of user names, I need to delete all of these users from Active Directory using the Remove-ADObject command. I am not very familiar with the syntax for this command - hoping you guys can help me here.

Import-Module activedirectory

$list = Import-CSV C:\Users\user\Desktop\deleteuserstest.csv

forEach ($item in $list) {
    $samAccountName = $item.samAccountName
    Remove-ADobject -Identity $samAccountName
}


推荐答案

您必须在删除时使用DN或GUID -ADObject。您可以执行以下操作:

You have to use DN or GUID with Remove-ADObject. You can do something like this:

Import-Module ActiveDirectory

$list = Import-CSV C:\Users\user\Desktop\deleteuserstest.csv

forEach ($item in $list) {
    $samAccountName = $item.samAccountName

    #Get DistinguishedName from SamAccountName
    $DN = Get-ADuser -Identity $Samaccountname -Properties DistinguishedName |
        Select-Object -ExpandProperty DistinguishedName

    #Remove object using DN
    Remove-ADObject -Identity $DN
}

这篇关于我需要使用导入的csv文件从Active Directory中删除用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆