Solved

AD Query for Users - Add line for Domain Admins

Posted on 2013-02-01
3
375 Views
Last Modified: 2013-02-08
I posted a question on here recently that was answered already for running a AD powershell query for Users and exporting to a clewan CSV shoing Title name department etc...  I am wionder if it is possible to add to this cmd to also pull all Domain Admins in AD and list them in their own category on the CSV.  Below is the cmd SUBSUN provided foir running the AD USer Query and below that is a Query I found for pulling the DOmain Admins.  I am having trouble combining them to make one CSV.

Thanks in Advanced for your help!





COMMAND FOR AD USER QUERY:

Get-ADUser -Filter * -Properties Title,Department,LastLogonDate,whenCreated,Enabled -SearchBase "DC=ad,DC=local" |
? {$_.Name -notlike "*ConfRm*" `
 -and $_.SamAccountName -notlike "*IG*" `
  -and $_.SamAccountName -notlike "*Mail*" `
 -and $_.SamAccountName -notlike "*QPM*" `
     -and $_.DistinguishedName -notmatch 'OU=SharedMailboxes,DC=AD,DC=Local' `
   
      -and $_.DistinguishedName -notmatch 'OU=ServiceAccounts,DC=AD,DC=Local'}  |
Select Name,Title,Department,LastLogonDate,whenCreated,Enabled |
Export-Csv "C:\myscripts\ADusers.csv" –NoTypeInformation





CMD for Domain ADMIN Query:
Get-ADGroupMember 'domain admins'
0
Comment
Question by:Twhite0909
[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
3 Comments
 
LVL 5

Expert Comment

by:coraxal
ID: 38845776
One approach would be to use PSCustom objects to combine users from both queries
 
$usersCol = @()
# Get AD users
$users = Get-ADUser -Filter * -Properties Title,Department,LastLogonDate,whenCreated,Enabled -SearchBase "DC=ad,DC=local" |
? {$_.Name -notlike "*ConfRm*" `
 -and $_.SamAccountName -notlike "*IG*" `
  -and $_.SamAccountName -notlike "*Mail*" `
 -and $_.SamAccountName -notlike "*QPM*" `
     -and $_.DistinguishedName -notmatch 'OU=SharedMailboxes,DC=AD,DC=Local' `
         -and $_.DistinguishedName -notmatch 'OU=ServiceAccounts,DC=AD,DC=Local'}
# Get Domain Admins
$domainAdminUsers = Get-ADGroupMember -Identity "Domain Admins"

foreach ($user in $users)
{
	$objTemp = New-Object PSObject -Property @{            
		NAME = $user.Name
		TITLE = $user.Title
		DEPARTMENT = $user.Department
		LASTLOGONDATE = $user.LastLogonDate
		WHENCREATED = $user.WhenCreated
		ENABLED = $user.Enabled
		DOMAINADMIN = $false
	}            
	    
	$usersCol += $objTemp
}

foreach ($domainadmin in $domainAdminUsers)
{
	$adminuser = Get-ADUser -Identity $domainadmin.distinguishedName -Properties Title,Department,LastLogonDate,whenCreated,Enabled
			
	$objTemp = New-Object PSObject -Property @{            
		NAME = $adminuser.Name
		TITLE = $adminuser.Title
		DEPARTMENT = $adminuser.Department
		LASTLOGONDATE = $adminuser.LastLogonDate
		WHENCREATED = $adminuser.WhenCreated
		ENABLED = $adminuser.Enabled
		DOMAINADMIN = $true
	}

	$usersCol += $objTemp	
	
}

$usersCol | Export-Csv "C:\myscripts\ADusers.csv" -NoTypeInformation

Open in new window

0
 

Author Comment

by:Twhite0909
ID: 38851305
Ok so now I just need to pull the name sof the current domain admins tand thats all.  However when I run the following:

Get-ADGroupMember 'domain admins'


I get Name, Samaccount,name Distinguished name, SID, Object Class and Ibject GUID

How can I export to CSV but only pull the NAME and not the rest?

Thanks
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38855948
Try..
Get-ADGroupMember 'domain admins' | Select Name | Export-Csv C:\Admins.csv -NoTypeInformation

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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