Bulk users move with condition check using powershell

Published: 16 June 2024
on channel: InfoAlias
68
2

To create a PowerShell script that searches for all enabled users with the department matching "Marketing" and moves them to a specific Organizational Unit (OU) named "Marketing", you can use the Active Directory module for PowerShell.

#powershell
#powershellscript
#activedirectory
#automation
#script


Explanation:
Import-Module ActiveDirectory: Loads the Active Directory module.
$targetOU: Specifies the Distinguished Name (DN) of the target OU.
Get-ADUser -Filter: Searches for all enabled users with the department attribute set to "Marketing".
Move-ADObject: Moves each user to the specified target OU.
Write-Output: Outputs the result of the operation for each user.
Prerequisites:
Run the script with sufficient privileges to read user properties and move objects in Active Directory.
Ensure the Distinguished Name (DN) of the target OU is correct.
Running the Script:
Save the script as MoveMarketingUsers.ps1.
Open PowerShell with administrative privileges.
Execute the script: .\MoveMarketingUsers.ps1.
Adjust the DC=yourdomain,DC=com part of the $targetOU variable to match your domain's naming context. If your domain is example.com, then it should be OU=Marketing,DC=infoalias,DC=local.


Watch video Bulk users move with condition check using powershell online without registration, duration hours minute second in high quality. This video was added by user InfoAlias 16 June 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 68 once and liked it 2 people.