powershell representing each OU as an array

Posted on 2013-10-25
Medium Priority
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


foreach ($ou in $ousers)

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

Question by:techdrive
LVL 40

Accepted Solution

Subsun earned 2000 total points
ID: 39601394
You can represent OU's like this...


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..
) | % {

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


Open in new window


Author Comment

ID: 39605354
thank you sir this is all that is needed

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If there is anything erroneous with Exchange Database, it causes a significant effect on email communication till the user remounts the database. Further, database crash directly affects Outlook users due to which they are unable to access their ema…
Seizing the Operation Master Roles in Windows Server 2016 in case of FSMO holder failure.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

619 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