Solved

powershell representing each OU as an array

Posted on 2013-10-25
2
390 Views
Last Modified: 2013-10-28
I was trying to see if there was a way I can take a fixed amount of OU's and run a command against them. I wanted to use an array (newbie here) but not sure how to represent each ou inside of this and run some commands inside of the foreach command. Any help would be appreciated, thanks


$OU=@(OU=USERS,OU=HR,DC=SOMECOMPANY,DC=COM, OU=USERS,OU=FINANCE,DC=SOMECOMPANY,DC=COM,OU=USERS,OU=SALES,DC=SOMECOMPANY,DC=COM,OU=USERS,OU=IT,DC=SOMECOMPANY,DC=COM)

$names=get-qaduser
foreach ($ou in $ousers)
{

$names -searchroot  $_ | set qaduser -passwordneverexpire $true

}
0
Comment
Question by:techdrive
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
You can represent OU's like this...

@(
"OU=USERS,OU=HR,DC=SOMECOMPANY,DC=COM"
"OU=USERS,OU=FINANCE,DC=SOMECOMPANY,DC=COM"
"OU=USERS,OU=SALES,DC=SOMECOMPANY,DC=COM"
"OU=USERS,OU=IT,DC=SOMECOMPANY,DC=COM"
)

Open in new window


If you can explain what you trying to achieve, then it will be better.. the code you posted is incorrect and confusing.. :-)

If you are trying to set the passwordneverexpire to $true for all users the the given OU's then you can try..
@(
"OU=USERS,OU=HR,DC=SOMECOMPANY,DC=COM"
"OU=USERS,OU=FINANCE,DC=SOMECOMPANY,DC=COM"
"OU=USERS,OU=SALES,DC=SOMECOMPANY,DC=COM"
"OU=USERS,OU=IT,DC=SOMECOMPANY,DC=COM"
) | % {

Get-QADUser -searchroot $_ | Set-QADUser -passwordneverexpire $true

}

Open in new window

0
 

Author Comment

by:techdrive
Comment Utility
thank you sir this is all that is needed
0

Featured Post

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now