Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Need AD Scripts to Process 3 Requirements

$
0
0

Project Brief:  We are creating users in an OU called Portal in AD and need powershell script(s) to update user attributes and then move them to predefined OU based on their Department field.  

 

Background: Users are being created via a custom web portal into AD and the AD user is created with a "token" in their Company field.

 

We have Universal Security Groups created that match these "token" values.  In each Universal Security Group's description field we have the name of the customer that it is assigned to.

 

We think this is a three step process

1) Add user to their respective Security Group.  This we were able to figure out.

$users = Get-ADUser -pr Company  -Filter * -SearchBase "ou=Portal,ou=iBASEt,dc=ibaset,dc=com"

foreach ($users in $users) {add-adgroupmember -Identity $users.Company $users.SamAccountName}

 

2) We now need take members of this security group - Update the department field of all its members to match the description of the security group.

 

3) Lastly look at the Users Department field and move them corresponding OU

 

We have tried the following and being new to powershell are stuck.

For step 2:

$portalusers = get-ADUser -pr Department -Filter * -SearchBase "ou=Portal,ou=iBASEt,dc=ibaset,dc=com"

foreach ($portalusers in $portalusers) {get-aduser $portalusers.DistinguishedName | move-adobject -targetpath OU=$portalusers.Department,OU=Customers,OU=iBASEt,DC=ibaset,DC=com}

 

We think the error has to do with the variable past the pipe not getting converted.  Found info on out-string but not sure who to make this work.


Viewing all articles
Browse latest Browse all 6937

Trending Articles