Create Domain User and remove domain user
#Created domain user and add user account to domain group
$domains = (get-adforest).domains
foreach($domain in $domains){
$accountname = ‘s-user-‘+($domain -split “.”)[0]+’-DA’
$accountpass = ‘P@ssword123456’ | ConvertTo-SecureString -Force -AsPlainText
Write-Output “Working on $domain – DA is $accountname”
New-ADUser -name $accountname -SamAccountName $accountname -AccountPassword $accountpass -Enabled $true -Server $domain
start-sleep -Seconds 5
Add-ADGroupMember -Identity “Domain Admins” -Members $accountname -Server $domain
}
#Find User account and delete user account
$domains = (get-adforest).domains
foreach($domain in $domains){
$accountname = ‘s-user-‘+($domain -split “.”)[0]+’-DA’
get-aduser $accountname -Server $domain | Remove-ADUser -Server $domain -Verbose -Confirm:$false
}#