Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

powershell representing each OU as an array

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

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

It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

972 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