none
Powershell - Parsing Get-AdPermission RRS feed

  • Question

  • Hi all I'm having something interesting happening and I can't seem to figure out what I've done wrong.  Here is the paired down code I working on.

    import-module activedirectory
    $senders=Get-ADPermission <mailbox> | ?{($_.extendedrights -like "*send-as*")} | Sort-Object name
    foreach ($sender in $senders) {
    $suser = "Domain\Testuser"
    $domain,$username = $suser.split('\')
    $test = $suser.substring(2,5)
    #$Dname = get-aduser $username | select name
    Write-Host "this is the name" $test $suser
    }

    When I run this code it works fine.

    import-module activedirectory
    $senders=Get-ADPermission <mailbox> | ?{($_.extendedrights -like "*send-as*")} | Sort-Object name
    foreach ($sender in $senders) {
    $suser = $senders.user
    $domain,$username = $suser.split('\')
    $test = $suser.substring(2,5)
    #$Dname = get-aduser $username | select name
    Write-Host "this is the name" $test $suser
    }

    I'm getting data in $suser but I can't do anything with the data in it

    When I run this I get an error on the split and/or substring.

    Any help would be appreciated.

    Thanks,

    Matt


    • Edited by Matt Inman Wednesday, October 17, 2018 3:31 PM formatting
    Wednesday, October 17, 2018 3:29 PM

All replies

  • Hi Matt,

    I'm not sure that if you noticed the code: $suser=$senders.user

    Please change the $senders.user

    to $sender.user

    And have you checked the $suser value is correctly? So I suspect this value is causing the problem. You can define this as an array of strings and loop it to test the split method. Like this:

    #$senders=Get-ADPermission 'v-simol@microsoft.com' | ?{($_.extendedrights -like "*send-as*")} | Sort-Object name
    $senders = 'Domain1\Testuser1', 'Domain2\Testuser2', 'Domain3\Testuser3'

    Regards,

    Simon


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.



    Thursday, October 18, 2018 10:31 AM