Solved

powershell representing each OU as an array

Posted on 2013-10-25
2
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39601394
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
ID: 39605354
thank you sir this is all that is needed
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A hard and fast method for reducing Active Directory Administrators members.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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