Reply To: powershell script for deleting ad user

Home Forums Scripting General Scripting powershell script for deleting ad user Reply To: powershell script for deleting ad user

Avatar
wullieb1
Moderator
#615080

Should be something as simple as

#Import the AD module

import-module ActiveDirectory

#Get the contents of the relevant text file

$users = (Get-Content -Path <PATH TO TEXT FILE>)

# Loop through the users in the text file and remove them

foreach($user in $users){

Remove-ADUser -Identity $user

}

What are you using for the user list? According to the MS docs it needs to be one of these
<ul style=”margin: 16px 0px 16px 38px; padding: 0px; box-sizing: inherit; color: #000000; font-family: ‘Segoe UI’, SegoeUI, ‘Segoe WP’, ‘Helvetica Neue’, Helvetica, Tahoma, Arial, sans-serif;”>
<li style=”outline: 0px; box-sizing: inherit; list-style: disc outside none;”>A Distinguished name
<li style=”outline: 0px; box-sizing: inherit; list-style: disc outside none;”>A GUID (objectGUID)
<li class=”” style=”outline: 0px; box-sizing: inherit; list-style: disc outside none;”>A Security Identifier (objectSid)
<li class=”” style=”outline: 0px; box-sizing: inherit; list-style: disc outside none;”>A SAM account name (sAMAccountName)

https://docs.microsoft.com/en-us/powershell/module/addsadministration/remove-aduser?view=win10-ps