Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

powershell representing each OU as an array

Posted on 2013-10-25
2
Medium Priority
?
400 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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Let's recap what we learned from yesterday's Skyport Systems webinar.
New style of hardware planning for Microsoft Exchange server.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
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
Suggested Courses

660 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