Solved

powershell script help

Posted on 2016-09-13
5
88 Views
Last Modified: 2016-09-14
any ideas on the below?

Get-ADUser -filter * -Properties DisplayName, EmailAddress, proxyAddresses, distinguishedName | select DisplayName, EmailAddress, proxyAddresses, distinguishedName | export-csv c:\temp\Email.csv –NoTypeInformation

i get the below in the export it has to do with multivalued attributes

proxyAddresses
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
0
Comment
Question by:Jorge Ocampo
[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
5 Comments
 
LVL 84

Expert Comment

by:oBdA
ID: 41796774
Try it like this:
Get-ADUser -filter * -Properties DisplayName, EmailAddress, proxyAddresses, distinguishedName | select DisplayName, EmailAddress, @{n='proxyAddresses'; e={$_.proxyAddresses -join ', '}}, distinguishedName | export-csv c:\temp\Email.csv –NoTypeInformation

Open in new window

0
 
LVL 69

Expert Comment

by:Qlemo
ID: 41796800
oBdA, your carriage return broken? :p
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41796827
Ah, less than 255 chars, that's barely over two lines in the default PS console ...
Get-ADUser -Filter * -Properties DisplayName, EmailAddress, ProxyAddresses, DistinguishedName |
	Select-Object -Property `
		DisplayName,
		EmailAddress,
		@{Name='ProxyAddresses'; Expression={$_.ProxyAddresses -join ', '}},
		DistinguishedName |
	Export-Csv -Path C:\temp\Email.csv –NoTypeInformation

Open in new window

0
 
LVL 2

Author Comment

by:Jorge Ocampo
ID: 41796858
@oBdA

didnt have any issues but is there a possible way to only get the primarysmtp "SMTP"
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41796903
Sure:
Get-ADUser -Filter * -Properties DisplayName, EmailAddress, ProxyAddresses, DistinguishedName |
	Select-Object -Property `
		DisplayName,
		EmailAddress,
		@{Name='PrimarySmtp'; Expression={(($_.ProxyAddresses | ? {$_ -clike 'SMTP:*'}) -split ':')[1]}},
		DistinguishedName |
	Export-Csv -Path C:\temp\Email.csv –NoTypeInformation 

Open in new window


Edit: renamed calculated property "ProxyAddresses" to "PrimarySmtp" for more clarity.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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 …
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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