1

I am a newbie to PowerShell and I am struggling to modify an output according to the way I want.

The command I run in MS Exchange Shell is this:

Get-Mailbox user1 | Get-ADPermission | ? {($_.ExtendedRights -like "*send-as*") -and -not ($_.User -like "NT AUTHORITY\SELF")} | Select User

The result I get from the above command is:

User              
----              
AGL\user4
AGL\user5
AGL\groupX

However I would like to obtain the output as:

User              
----              
user4
user5
groupX

Is it possible to do this?

Thanks heaps in advance.

MWH
  • 399
  • 1
  • 5
  • 19

2 Answers2

1

For this, use a Calculated Property to output the objects with their names only:

Get-Mailbox -Identity user1 | 
    Get-ADPermission | 
    Where-Object {($_.ExtendedRights -like "*send-as*") -and ($_.User -ne "NT AUTHORITY\SELF")} | 
    Select-Object @{Name = 'User'; Expression = {$_.User.Split("\",2)[1]}}
Theo
  • 57,719
  • 8
  • 24
  • 41
0

After a little testing, You can try

(Get-Mailbox user1 | Get-ADPermission | ? {($_.ExtendedRights -like "*send-as*") -and -not ($_.User -like "NT AUTHORITY\SELF")} | Select User).TrimStart("AGL\")

If that doesn't work you can try

$Rights = Get-Mailbox user1 | Get-ADPermission | ? {($_.ExtendedRights -like "*send-as*") -and -not ($_.User -like "NT AUTHORITY\SELF")} | Select User

$Rights = $Rights.TrimStart("AGL\")

The trim will trim the start up to the point of the back slash, as long as the string stays the same.

Fluffarmy223
  • 47
  • 1
  • 5