none
Hashtable-to-Object conversion is not supported RRS feed

  • Question

  • I am trying to remove a fake address (LSMTP) from all the mailboxes in our Office 365 tenant. I found the following script that seems to do exactly what I am wanting:

    ForEach ($mbx in (Get-Mailbox -ResultSize Unlimited)) {

          $addrs = $mbx.EmailAddresses | Where {$_.Prefixstring -ne "LSMTP"}

          Set-Mailbox $mbx -EmailAddresses $addrs

    But I receive the following error:

    Cannot process argument transformation on parameter 'Identity'. Cannot convert value "Oosthuizen Riaan" to type
    "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Cannot convert hashtable to an object of the
    following type: Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter. Hashtable-to-Object conversion is not
    supported in restricted language mode or a Data section."
        + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
        + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
        + PSComputerName        : outlook.office365.com

    Any help would be much appreciated

    Friday, September 8, 2017 12:23 PM

All replies

  • See if the following will work for you:

    ForEach ($mbx in (Get-Mailbox -ResultSize Unlimited)) {
        $addrs = [array]($mbx.EmailAddresses | ? {$_.Prefixstring -ne "LSMTP"} | % { $_.ProxyAddressString })
        Set-Mailbox $mbx -EmailAddresses $addrs
    }

    I've taken the addresses (except for your LSMTP, using your filter) and retained only the proxy address string (such as SMTP:alias@company.com).  This action makes it so you no longer have a hash-table.  Then, I've made sure these are stored as an array in the $addrs variable (while it shouldn't be necessary, it also shouldn't hurt).  If this doesn't work, let me know - it worked on my test mailbox.


    Will Martin ...
    -join ('77696c6c406d617274696e2d66616d696c6965732e6f7267' -split '(?<=\G.{2})' | ? { $_ } | % { [char][int]"0x$_" })

    Friday, September 8, 2017 12:56 PM
  • Unfortunately not, I get back the error:

    Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value
    "System.Collections.ArrayList" to type "Microsoft.Exchange.Data.ProxyAddressCollection". Error: "Le raccolte
    MultiValuedProperty non possono contenere valori NULL.
    Parameter name: item"
        + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
        + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
        + PSComputerName        : outlook.office365.com

    Friday, September 8, 2017 1:13 PM
  • Airloca, it's possible that your original error ("Cannot convert value "Oosthuizen Riaan" to type
    "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter"") wasn't because of the list, but due to how you referenced the mailbox.  See if the following will work:

    ForEach ($mbx in (Get-Mailbox -ResultSize Unlimited)) {
        $addrs = $mbx.EmailAddresses | ? {$_.Prefixstring -ne "LSMTP"}
         Set-Mailbox $mbx.Alias -EmailAddresses $addrs
    }

    Note, I've just added ".Alias" to your $mbx from your original script.


    Will Martin ...
    -join ('77696c6c406d617274696e2d66616d696c6965732e6f7267' -split '(?<=\G.{2})' | ? { $_ } | % { [char][int]"0x$_" })

    Friday, September 8, 2017 1:27 PM
  • Perfect, that worked!!!!! I receive now the error that I cannot apply the change because the objects are synchronized with my on-prem AD but that was expected. Now I can stop dirsync and launch the command.

    Thanks.

    Friday, September 8, 2017 1:41 PM
  • If you are in a hybrid organization, you should be able to run these same commands against your on-prem Exchange systems, but with Get- and Set-RemoteMailbox instead of Get- and Set-Mailbox.

    Will Martin ...
    -join ('77696c6c406d617274696e2d66616d696c6965732e6f7267' -split '(?<=\G.{2})' | ? { $_ } | % { [char][int]"0x$_" })

    Monday, September 11, 2017 12:04 PM