Solved

need assistance with a Quest AD cmdlets script

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
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…
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…

707 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

20 Experts available now in Live!

Get 1:1 Help Now