Hi All,
Need your help.
I am trying to export report on “send on behalf” on 0365 mailboxes, i want the output in multiple rows instead i am getting in singe row.
For eg:
Identity GrantonBehalf
User1 ABC XYZ UVW
I like to have the output in multiple rows
Identity GrantonBehalf
User1 ABC
User1 XYZ
User1 UVW
The code i use the below
Get-Mailbox -Resultsize Unlimited | Where {$_.GrantSendOnBehalfTo -ne ""} | Select Identity, GrantSendOnBehalfTo |
Export-Csv -Path C:\temp\SendOnBehalf.csv -NoTypeInformation
Thanks
Shanmugavel
Olaf
October 11, 2022, 6:30pm
2
Instead of the Select-Object
you need a loop to iterate over all elements you have in the property GrantSendOnBehalfTo
.
Hi Olaf,
I tried the below,
I am getting only the ouput for user and for others i am getting system.object , please help
$GrantSendOn= Get-Mailbox -resultsize unlimited| where {($_.GrantSendOnBehalfTo -ne "")}
$Out=foreach ($user in $GrantSendOn.GrantSendOnBehalfTo) {
$obj= New-Object System.Object
$obj|Add-Member NoteProperty eMail$GrantSendOn.WindowsEmailAddress
$obj|Add-Member NoteProperty DisplayName $GrantSendOn.DisplayName
$obj|Add-Member NoteProperty User $user
$obj }
$Out| Export-Csv -Path "c:\temp\sendonbehalfpermissions.csv" –NoTypeInformation
Thanks
Shanmugavel
Olaf
October 12, 2022, 7:18am
4
You need a nested loop and you should not use Add-Member
This should do the trick:
$MailboxList =
Get-Mailbox -resultsize unlimited |
Where-Object -Property GrantSendOnBehalfTo -NE -Value ''
$Out =
foreach ($Mailbox in $MailboxList) {
foreach ($GrantSendOn in $Mailbox.GrantSendOnBehalfTo) {
[PSCustomObject]@{
eMail = $GrantSendOn.WindowsEmailAddress
DisplayName = $GrantSendOn.DisplayName
User = $Mailbox
}
}
}
$Out |
Export-Csv -Path 'c:\temp\sendonbehalfpermissions.csv' –NoTypeInformation