Solved

need assistance with a Quest AD cmdlets script

Posted on 2013-07-01
5
429 Views
Last Modified: 2013-07-01
Hello, I need to modify the following Quest AD CMDlets script to key on the following attribute:

l <- location  = UK

currently the script only targets an OU, i need it to only pull results for accounts with the "l" field = UK.

# Instruction to add Quest Powershell Snap-in
Add-PSSnapin quest.ActiveRoles.admanagement
$OU="mydomain.com/Users"
$Logfile="C:\result.csv"
Get-Qaduser -SizeLimit 0 -SearchRoot $OU | 
select mail,sAMAccountName,displayName,telephoneNumber,mobile,l,givenName,sn |
Export-Csv $Logfile -NoTypeInformation
#Email the data
$EmailBody = "User List Attached"
$message = New-Object System.Net.Mail.MailMessage –ArgumentList reports@mydomain.com,LDAP-Reports-AdHoc@mydomain.com,'AD DS Export Report', $EmailBody
$smtp = New-Object System.Net.Mail.SMTPClient –ArgumentList smtp.mydomain.com
$Attachment = New-Object System.Net.Mail.Attachment($Logfile)
$message.Attachments.Add($attachment)
$smtp.Send($message)
Start-Sleep 1
$Attachment.Dispose()
$Message.Dispose()
#Remove the temp file
if (Test-Path $Logfile) {Remove-Item $Logfile} 

Open in new window

0
Comment
Question by:siber1
[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
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
BT15 earned 500 total points
ID: 39290572
try this:

# Instruction to add Quest Powershell Snap-in
Add-PSSnapin quest.ActiveRoles.admanagement
$OU="mydomain.com/Users"
$Logfile="C:\result.csv"
Get-Qaduser -SizeLimit 0 -SearchRoot $OU | 
select mail,sAMAccountName,displayName,telephoneNumber,mobile,l,givenName,sn | ? {$_.l -eq "UK"}|
Export-Csv $Logfile -NoTypeInformation
#Email the data
$EmailBody = "User List Attached"
$message = New-Object System.Net.Mail.MailMessage –ArgumentList reports@mydomain.com,LDAP-Reports-AdHoc@mydomain.com,'AD DS Export Report', $EmailBody
$smtp = New-Object System.Net.Mail.SMTPClient –ArgumentList smtp.mydomain.com
$Attachment = New-Object System.Net.Mail.Attachment($Logfile)
$message.Attachments.Add($attachment)
$smtp.Send($message)
Start-Sleep 1
$Attachment.Dispose()
$Message.Dispose()
#Remove the temp file
if (Test-Path $Logfile) {Remove-Item $Logfile} 

Open in new window

0
 

Author Comment

by:siber1
ID: 39290590
hi, just tried and here is the error generated:
Expressions are only allowed as the first element of a pipeline.
0
 

Author Comment

by:siber1
ID: 39290599
sorry forgot to add the ? variable. running it now in the lab.
0
 
LVL 7

Expert Comment

by:BT15
ID: 39290606
the "?" is the same as saying "where" or "where-object"
0
 

Author Closing Comment

by:siber1
ID: 39290721
works great! thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
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
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

710 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