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
Solved

need assistance with a Quest AD cmdlets script

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

791 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