Bulk un-hide users from GAL

This topic contains 9 replies, has 4 voices, and was last updated by Profile photo of BlackBoxCoder BlackBoxCoder 5 months, 3 weeks ago.

  • Author
    Posts
  • #59385
    Profile photo of Siddra
    Siddra
    Participant

    I have run this command to export a list of users:

    Get-Mailbox –ResultSize Unlimited | Where {$_.HiddenFromAddressListsEnabled -eq $True} | Select Name, HiddenFromAddressListsEnabled | export-csv c:\hiddenGAL.csv

    This part works fine but when I run the second part of the code to import the users and set the mailbox to be hidden as false, I get an error. The code is:
    $users = import-csv c:\hiddenGAL.csv | For each($_ in $users) {Set-mailcontact $_.identity -HiddenFromAddressListsEnabled $false}

    error: Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo : InvalidData: (:) [Set-MailContact], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-MailContact
    + PSComputerName : ps.outlook.com

  • #59389
    Profile photo of random commandline
    random commandline
    Participant

    Your logic is not correct. If I am not mistaken, the '-Identity' parameter does not accept pipeline input.

    $users = import-csv c:\hiddenGAL.csv
    foreach ($user in $users){
    Set-mailcontact $user.Name -HiddenFromAddressListsEnabled:$false
    }
    
    • #59397
      Profile photo of Siddra
      Siddra
      Participant

      thanks but I'm getting a different error now:

      The operation couldn't be performed because object 'Sara Manson' couldn't be found on
      'DB3PR02A002DC05.EURPR02A002.prod.outlook.com'.
      + CategoryInfo : NotSpecified: (:) [Set-MailContact], ManagementObjectNotFoundException
      + FullyQualifiedErrorId : [Server=HE1PR0201MB2027,RequestId=00816075-1999-4940-8430-e44d22657b31,TimeStamp=12/5/20
      16 2:43:13 PM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 11A63030,Microsoft.Exchange.Management.R
      ecipientTasks.SetMailContact
      + PSComputerName : ps.outlook.com

    • #59400
      Profile photo of Ron
      Ron
      Participant

      You should capture samaccountname, alias or distinguishedname instead. Name is the CN and might not be unique.

    • #62622
      Profile photo of Siddra
      Siddra
      Participant

      Hi,

      I have ammended the original code to export the user principal name instead of name and this works exactly like i want it to. the above code when importing the csv throws an error please help:

      $users = import-csv c:\hiddenGALnew.csv
      foreach ($user in $users){
      Set-mailcontact $user.UserPrincipalName –HiddenFromAddressListsEnabled $false
      }

      the error is:

      The operation couldn't be performed because object 'username@xxxxxx.org' couldn't be found on
      'DB3PR02A002DC05.EURPR02A002.prod.outlook.com'.
      + CategoryInfo : NotSpecified: (:) [Set-MailContact], ManagementObjectNotFoundException
      + FullyQualifiedErrorId : [Server=HE1PR0201MB2027,RequestId=8d7899e2-3098-4228-aee4-adbc16b239af,TimeStamp=1/25/20
      17 11:27:49 AM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] A2F21E7,Microsoft.Exchange.Management.R
      ecipientTasks.SetMailContact
      + PSComputerName : outlook.office365.com

  • #62626
    Profile photo of Ron
    Ron
    Participant

    I don't see a UPN in the help for Set-MailContact. I would use the DistinguishedName or GUID to make sure you are specifying the correct, unique ID.

    • #62988
      Profile photo of Siddra
      Siddra
      Participant

      Hi

      I did this based on distinguished name and I still get an error

      Cannot bind argument to parameter 'Identity' because it is null.
      + CategoryInfo : InvalidData: (:) [Set-MailContact], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-MailContact
      + PSComputerName : outlook.office365.com

      can you help me with the full code – im not sure where it is going wrong.

      Thanks

  • #62994
    Profile photo of BlackBoxCoder
    BlackBoxCoder
    Participant

    I would try:

    Get-Mailbox -Identity $user | Set-mailcontact –HiddenFromAddressListsEnabled $false

    BR,
    BBC

    • #63003
      Profile photo of Siddra
      Siddra
      Participant

      Hi BlackBoxCoder

      Im really struggling with this one – please can you help with the full code. Below is the code from the thread

      $users = import-csv c:\hiddenGAL.csv
      foreach ($user in $users){
      Set-mailcontact $user.Name -HiddenFromAddressListsEnabled:$false
      }

      From your input would it be
      ****************$users = import-csv c:\hiddenGAL.csv
      foreach ($user in $users){
      Get-Mailbox -Identity $user | Set-mailcontact –HiddenFromAddressListsEnabled $false
      } ************* i tried this and still get errors

    • #63007
      Profile photo of BlackBoxCoder
      BlackBoxCoder
      Participant

      hey, I am not a big friend of 1line-Archivments, but why not like this:

      Get-Mailbox –ResultSize Unlimited | Where {$_.HiddenFromAddressListsEnabled -eq $True} | Set-mailcontact –HiddenFromAddressListsEnabled:$false

You must be logged in to reply to this topic.