• Home
  • Blog
  • General
  • Powershell
  • About Me
  • Contact US

Creating and Removing domain accounts in each domain in a forest

6 April 2022 jeevanbobba General, Powershell, Windows 0

Created domain account in each domain add it to domain admin group

$domains = (get-adforest).domains
foreach($domain in $domains){
$accountname = ‘s-coe-‘+($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
}

Remove domain account in each domain

$domains = (get-adforest).domains
foreach($domain in $domains){
$accountname = ‘s-coe-‘+($domain -split “.”)[0]+’-DA’
get-aduser $accountname -Server $domain | Remove-ADUser -Server $domain -Verbose -Confirm:$false
}

  • Citrix Xen Desktop
  • Citrix Xenapp
  • creating account powershell
  • domain account
  • get-aduser
  • new-aduser
  • Powershell
  • remove-aduser
Previous

Created ISO image using PowerShell

Next

Get DC replication time response

Recent Posts

  • AI Can Write Your Code. Can Your Team Still Ship It?
  • Convert a PowerShell .PS1 File to EXE: A Practical PS2EXE Guide
  • The Remote Computer requires network-level authentication
  • Git Command Cheat Sheet for Beginners
  • Mastering Credential Management in PowerShell: A Comprehensive Guide

Recent Comments

No comments to show.

Archives

  • October 2026
  • August 2026
  • July 2025
  • February 2025
  • April 2024
  • August 2022
  • June 2022
  • April 2022
  • March 2022
  • August 2021
  • January 2021
  • December 2020
  • June 2020
  • May 2020
  • April 2019
  • January 2019
  • August 2018
  • July 2018
  • May 2018
  • February 2018
  • January 2018
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • April 2017
  • January 2017
  • December 2016
  • November 2016
  • August 2016
  • July 2016
  • May 2016
  • April 2016
  • March 2016
  • October 2015

Categories

  • Azure
  • Citrix
  • General
  • Git
  • Linux
  • Powershell
  • Uncategorized
  • Vmware
  • Windows

Copyright © 2026 Jeevan Bobba. All Rights Reserved.