none
Remove GrantSendOnBehalfTo disabled user accounts - A novice at scripting RRS feed

  • Question

  • Hello.  Can anyone help please

    In our exchange 2010 environment we have users who are granted send on behalf to access.  Obviously some users leave and I m finding that there are ghosts left behind which are causing issues with our team who add users into the grantsendonbehalfto option using the EMC.  Using the log view we coy out the command and then remove the disabled user from the command and then paste this into an Exchange Powershell command line.  This wrks because it is doing what Exchange EMC does which is rewrites the -GrantSendOnBehalfTo option in it new entirety.  

    The problem occurs because I need to remove these en-mass from approx 700 plus accounts.  

    I have tried to modify one user in order to get the script to work but it doesn't.

    This is the error message that happens when I run the script below against a known account with at least 2 disabled users in:-

    Couldn't find object "xxxxxxxx.xx.xxxxxxx.xxx.xx/DisabledUsers/2013-08/Gaynor Collins-Punter". Please make sure that i
     was spelled correctly or specify a different object. Reason: The recipient xxxxxxxx.xx.xxxxxxx.xxx.xx/DisabledUsers/2
    13-08/Gaynor Collins-Punter isn't the expected type.
        + CategoryInfo          : NotSpecified: (:) [], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : F6498844
        + PSComputerName        : ex02-0029.xx.xxxxxxx.xxx.xx

    Am running the script from my local PC

    This is the script I have used.

    # Gather info use get-mailbox -resultsize unlimited

    $mailboxes = Get-Mailbox zplew1 Foreach($mailbox in $mailboxes) { for($i = ($mailbox.GrantSendOnBehalfTo.count)-1; $i -ge 0; $i--) { $address=$mailbox.GrantSendOnBehalfTo[$i] $addressString=$address.addressString If($addressString -like "*disabled*") { $mailbox.GrantSendOnBehalfTo.removeat($i) $info >> "C:\Scripts\grantsendonbehalfto.csv" } } $mailbox |set-mailbox -GrantSendOnBehalfTo $mailbox.grantsendonbehalfto }

    If you requiere any more info please let me know.

    Thursday, November 27, 2014 1:06 PM

Answers

All replies

  • #1 - I recommend posting in xchange forum fo rhow to do this

    #2 - Wen an account is disabled most on the information in the object is hidden.  YOu would need to undelete to use the object.

    #3 - Get list as text and validaye al values are not deleted accounts.  Remove deleted and save back.


    ¯\_(ツ)_/¯

    Thursday, November 27, 2014 1:54 PM
  • Cheers for that.  I'll post it on the Exchange forum.
    • Marked as answer by BillBroom Thursday, November 27, 2014 2:40 PM
    Thursday, November 27, 2014 2:26 PM