?
Solved

Using Powershell against Active Directory

Posted on 2010-11-15
8
Medium Priority
?
648 Views
Last Modified: 2012-05-10
Hi

When we had Windows 2003 servers, I used the Quest ActiveRoles product quite a lot to run Powershell written queries against our Active Directory.

We now have Windows 2008 R2 servers, and I understand those commands are included in the native Powershell installation?

I was wondering someone could help me with a query I had -

We have about 500 service accounts in our AD, all starting with the word "service". They are also located in the same OU (domain>Special>Service)

I would like to run a Powershell query to list all of this accounts into a text file. I would also like there to be a carriage return after each entry.

Does anyone know how I can achieve this?
0
Comment
Question by:tomd1976
8 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 34138766

the 2008R2 cmdlets are real similar to the ones quest has

get-aduser -searchbase "OU=Service,OU=Special,DC=Domain,DC=local" -Filter * | select name | export-csv c:\servcieaccounts.csv
0
 
LVL 5

Assisted Solution

by:daveTechSearch
daveTechSearch earned 400 total points
ID: 34138950
I believe you also need to use the AD Management gateway service on at least one DC:
http://technet.microsoft.com/en-us/magazine/ee914610.aspx

Tutorial on managing AD with the cmdlets (video):
http://technet.microsoft.com/en-us/windowsserver/ff730325.aspx

Download for the web service:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=008940c6-0296-4597-be3e-1d24c1cf0dda&displaylang=en
0
 
LVL 5

Accepted Solution

by:
mittermueller earned 800 total points
ID: 34139104
Get-ADUser -Filter { CN -like "Service*" } | select name | export-csv c:\sas.csv
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tomd1976
ID: 34139612
Thanks all

With Quest, I needed to attach to a DC/GC with a user account, do I need to do that here too?
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34139656
If you are running from your workstation you have a few options

1. use windows 7 or 2008R2 and add the AD module
import-module activedirectory

2. Use WinRM to remote into the DC if you have that enabled.
0
 

Author Comment

by:tomd1976
ID: 34139952
Thanks all, I used this and it works fine:

Get-ADUser -Filter { CN -like "Service*" } | select name | export-csv c:\sas.csv

A couple of related questions...

If I run:

Get-ADUser -Filter { CN -like "Service*" }

Then I get a list of account with the word "service" in them.  Couple of questions/;

1. Is it possible to have the search query look for entries that start with "service" rather than just contain it?

2.  The results only show certain attributes? How can I expand that to include attributes such as email address?
0
 
LVL 27

Assisted Solution

by:KenMcF
KenMcF earned 800 total points
ID: 34139986
You can use this depending on how the account are setup.

Get-ADUser -Filter { Name -like "Service*" }

To get other attribues

Get-ADUser -Filter { Name -like "Service*" } -properties mail  | select Name, mail

0
 

Author Comment

by:tomd1976
ID: 34140066
Perfect, thanks so much!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
Screencast - Getting to Know the Pipeline

840 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