PowerShell as an AD user management tool

PowerShell as an AD user management tool

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. 

Creating AD user

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}

Modifying an AD user

Import-CSV test.csv | foreach {Set-ADUser -Identity $_.sAMAccountName -Description "testing description"}

Adding Group Membership (Adding user to a group)

Import-CSV test.csv | foreach {Add-ADGroupMember -Identity "Domain guests" -Members $_.sAMAccountName}

Enable/disable AD user

Enable-ADAccount -identity testUser
Disable-ADAccount -identity testUser

Moving an AD user

Move-ADObject -Identity "CN=testuser1,DC=Domain,DC=com" -TargetPath "OU=testOU,DC=Domain,DC=Com"

Changing password

Set-ADAccountPassword -Identity testuser -NewPassword new123 -OldPassword old123

Unlocking AD account

Unlock-ADAccount -Identity testuser

Removing an AD user

Remove-ADUser -Identity testuser

Creating an Office 365 user

New-Msoluser -DisplayName testuser -userprincipalname testuser@test.onmicrosoft.com -usagelocation US -licenseAssignment test:ENTERPRISEPACK


    • Related Articles

    • How to find unused Exchange Online mailboxes

      What are unused Exchange Online mailboxes and how to identify them? Unused Exchange Online mailboxes are user mailboxes which are currently not being used by their users. There are 3 ways in which we can identify if a mailbox is unused or not. They ...
    • PowerShell as an AD bulk user management tool

      Bulk AD user creation can be quite a challenge for Active Directory (AD) administrators day in, day out. Many administrators use Microsoft's PowerShell to create users and perform other such basic AD user management tasks. Below are some key ...
    • PowerShell as an AD group management tool

      Group management can be quite a challenge for Active Directory (AD) administrators day in, day out. Many administrators use Microsoft's PowerShell technology to perform basic AD user management tasks. Below are some key PowerShell scripts and ...
    • Generate an Activity Report for Microsoft 365 Groups and Teams

      Introduction The activity reports available for Microsoft 365 groups and Teams can be beneficial for administrators in an organization. Microsoft 365 teams group activity reports provide insight into group activities, group workloads, group counts, ...
    • PowerShell for AD user reports

      Real-time insights on user account status and activity can help AD  administrators manage accounts better. Many administrators use Microsoft's PowerShell scripts to generate Active Directory reports  and pull detailed information. Below are some ...