User management can be quite a challenge for Active Directory (AD) administrators day in and day out. Many administrators use Microsoft's PowerShell technology to perform basic AD user management tasks. Below are some key PowerShell scripts and commands for working with AD users.
Import-CSV test.csv | foreach {New-ADUser -SamAccountName $_.SamAccountName -Name $_.Name -Surname $_.Surname -GivenName $_.GivenName -Path "OU=Finance,OU=UserAccounts,DC=FABRIKAM,DC=COM" -AccountPassword (ConvertTo-SecureString -AsPlainText $_.password -Force) -Enabled $true}
Import-CSV test.csv | foreach {Set-ADUser -Identity $_.sAMAccountName -Description "testing description"}
Import-CSV test.csv | foreach {Add-ADGroupMember -Identity "Domain guests" -Members $_.sAMAccountName}
Enable-ADAccount -identity testUser
Disable-ADAccount -identity testUser
Move-ADObject -Identity "CN=testuser1,DC=Domain,DC=com" -TargetPath "OU=testOU,DC=Domain,DC=Com"
Set-ADAccountPassword -Identity testuser -NewPassword new123 -OldPassword old123
Unlock-ADAccount -Identity testuser
Remove-ADUser -Identity testuser
New-Msoluser -DisplayName testuser -userprincipalname testuser@test.onmicrosoft.com -usagelocation US -licenseAssignment test:ENTERPRISEPACK