Solved

need assistance with a Quest AD cmdlets script

Posted on 2013-07-01
5
425 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
  • 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

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Question has a verified solution.

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

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now