Bulk un-hide users from GAL

Welcome Forums General PowerShell Q&A Bulk un-hide users from GAL

This topic contains 10 replies, has 5 voices, and was last updated by

 
Participant
1 year, 10 months ago.

  • Author
    Posts
  • #59385

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 10
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

      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
      Ron

      Participant
      Points: 0
      Rank: Member

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

    • #62622

      Participant
      Points: 0
      Rank: Member

      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
    Ron

    Participant
    Points: 0
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

      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

    Participant
    Points: 0
    Rank: Member

    I would try:

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

    BR,
    BBC

    • #63003

      Participant
      Points: 0
      Rank: Member

      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

      Participant
      Points: 0
      Rank: Member

      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
  • #111019

    Participant
    Points: 0
    Rank: Member

    Hello,

    I came across this post and I thought I would add an update.  If you are connecting to Office 365 for contact maintenance, you can use the following.  I just tested it and it functioned for me very well.

    #This script connects you to the Exchange Online Power Shell
    
    #
    
    ##$Cred = Get-Credential will prompt you for a username and password.
    
    #
    
    ###The username is your email address associated with the account you are trying to access.
    
    #
    
    ####The password is the password associated with the account you are trying to access.
    
    #
    
    #####If you use MFA, you will need to create an app password in Office365.
    
    #
    
    #This PowerShell should be run with administrator privelages.
    
    #
    
    Set-ExecutionPolicy RemoteSigned
    
    $Cred = Get-Credential
    
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Cred -Authentication Basic -AllowRedirection
    
    Import-PSSession $Session -DisableNameChecking
    
    #
    
    #Once connected, run the following command to gather all contacts in the variable $Contacts
    
    #
    
    $Contacts = Get-MailContact
    
    #
    
    #Run the following command to ammend their status "-HiddenFromAddressListEnabled"
    
    #
    
    ##If you want to make them all visible, set the $true variable to $false
    
    #
    
    ##If you want to make them all hidden, keep the $true variable as $true
    
    #
    
    $Contacts | Foreach {Set-mailcontact $_.alias -HiddenFromAddressListsEnabled $true}
    
    #If some of the contacts are already set to the parameter you choose, they will come back with a warning that nothing changed for the given account
    
    #
    
    ##Ex. WARNING: The command completed successfully but no settings of 'FirstName LastName' have been modified.
    
    #
    
    #To close the session run the following command
    
    #Remove-PSSession $Session
    

The topic ‘Bulk un-hide users from GAL’ is closed to new replies.