Hi David,
After consulting our related team, we can achieve your goal via the following “piped-command”:
Get-Recipient |ft Displayname, RecipientType, PrimarySmtpAddress, EmailAddresses –Wrap
Thanks,
Gary
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The following Powershell command does not give the results expected:
get-recipient | Select-Object -property DisplayName -ExpandProperty emailaddresses
As per (example 2):
https://msdn.microsoft.com/powershell/reference/5.1/Microsoft.PowerShell.Utility/Select-Object
What am I doing wrong?
Thanks in advance
David (Nobby) Barnes
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Hi David,
After consulting our related team, we can achieve your goal via the following “piped-command”:
Get-Recipient |ft Displayname, RecipientType, PrimarySmtpAddress, EmailAddresses –Wrap
Thanks,
Gary
Hi Gary,
thanks for the response on this..
I tried this and cannot seem to find a way to expand the emailaddresses object list
I tried the CSV output and all the email addresses are in one single cell for each user
get-recipient | Select-Object -ExpandProperty emailaddresses
Gets the closest but lacks the associated 'Display Name'
As I said get-recipient is not allowing the correct results when -expandproperty is used
even for a single user
EG:
get-recipient <user> | Select-Object -property DisplayName -ExpandProperty emailaddresses | FL
If I use Get-process the -expandproperty usage does not break the command
EG:
Get-Process Explorer | Select-Object -Property ProcessName -ExpandProperty Modules | Format-List
ProcessName : explorer
ModuleName : Explorer.EXE
FileName : C:\WINDOWS\Explorer.EXE
BaseAddress : 140696870060032
ModuleMemorySize : 4661248
EntryPointAddress : 140696870710112
FileVersionInfo : File: C:\WINDOWS\Explorer.EXE
InternalName: explorer
OriginalFilename: EXPLORER.EXE.MUI
FileVersion: 10.0.14393.0 (rs1_release.160715-1616)
FileDescription: Windows Explorer
Product: Microsoft® Windows® Operating System
ProductVersion: 10.0.14393.0
Debug: False
Patched: False
PreRelease: False
PrivateBuild: False
SpecialBuild: False
Language: English (United Kingdom)
Site :
Container :
Size : 4552
Company : Microsoft Corporation
FileVersion : 10.0.14393.0 (rs1_release.160715-1616)
ProductVersion : 10.0.14393.0
Description : Windows Explorer
Product : Microsoft® Windows® Operating System
ProcessName : explorer
ModuleName : ntdll.dll
FileName : C:\WINDOWS\SYSTEM32\ntdll.dll
BaseAddress : 140722574000128
ModuleMemorySize : 1904640
EntryPointAddress : 0
FileVersionInfo : File: C:\WINDOWS\SYSTEM32\ntdll.dll
InternalName: ntdll.dll
OriginalFilename: ntdll.dll.mui
FileVersion: 10.0.14393.206 (rs1_release.160915-0644)
FileDescription: NT Layer DLL
Why doesn't get-recipient expand like this?
I note that ProcessName is repeated and listed ahead of each module as the module list is expanded.
Or am I missing something?
Or have I found a bug?
Thanks for looking at this
David (Nobby) Barnes
Hi Gary,
Yes, I'd got that far but wanted to expand the emailaddresses object and cannot seem to.
There must be a simpler way using pipe commands, but I cannot get the -expandproperty to work correctly.
This codelet does work but doesn't output to CSV well.
$Array = @()
foreach ($user in get-recipient)
{
#Write-output $User
$USR = (get-recipient $user.name | select DisplayName, Recipienttype, primarysmtpaddress)
$PSMTP = $USR.primarysmtpaddress
#$EMA = get-recipient $user | select -expandproperty emailaddresses | where { $_ -like “smtp:*” -and $_ -ne “smtp:$PSMTP” -and $_ -notlike “*onmicrosoft*” }
$EMA = get-recipient $user.name | select -expandproperty emailaddresses | where { $_ -like “smtp:*” -and $_ -ne “smtp:$PSMTP” }
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $USR.DisplayName
$obj | Add-Member -MemberType NoteProperty -Name “RecipientType” -Value $USR.recipienttype
$obj | Add-Member -MemberType NoteProperty -Name “PrimarySMTPAddress” -Value $PSMTP
foreach ($Emaddr in $EMA)
{
$EML = $Emaddr -split “:”,2
$obj | Add-Member -MemberType NoteProperty -Name “EmailAddress” -Value $EML[1]
$array += $obj
$obj = New-Object PSObject
}
}
Write-Output $array | FT
There must be a direct 'piped-command' way of achieving this.
Thanks
David (Nobby) Barnes
Hello David,
I think we don’t need to expand the emailaddresses to get the result.
Try mine:
Get-Recipient -ResultSize unlimited |Select-Object displayname,emailaddresses |Format-Table -wrap
The format maybe not that ideal, but we can get the same result.
Best,
Alison