-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet-UserHiddenFromGal.ps1
51 lines (40 loc) · 1.36 KB
/
Set-UserHiddenFromGal.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This script will enable or disable the msExchHideFromAddressLists
# AD user parameter, effectively hiding or unhiding the user
# from the GAL.
#
# Accepts a CSV file containing a list of UserPrincipalNames with
# a header of UserPrincipalName.
#
# [email protected] 06092019
#
# Usage:
# To hide users from GAL - .\Set-UserHiddenFromGal.ps1 -Enabled $true -CSVPath C:\Temp\UserList.csv
# To unhide users from GAL - .\Set-UserHiddenFromGal.ps1 -Enabled $false -CSVPath C:\Temp\UserList.csv
#region Script Parameters
# -----------------------
[CmdletBinding(SupportsShouldProcess=$True)]
Param (
[parameter(
Mandatory=$true,
HelpMessage='Enable or disable msExchHideFromAddressLists parameter')]
[bool]$Enabled,
[parameter(
Mandatory=$true,
HelpMessage='Path to list of users')]
[string]$CSVPath
)
Import-Module ActiveDirectory
#endregion
#region Variables
#----------------
$HiddenUsers = Import-Csv -Path $CSVPath
#endregion
#region Program
#--------------
foreach ($User in $HiddenUsers) {
# Set the msExchHideFromAddressLists parameter based on input.
$upn = $User.UserPrincipalName
if ($Enabled) {Write-Host "Hiding user $upn"} else {Write-Host "Unhiding user $upn"}
Set-ADUser $upn -Replace @{msExchHideFromAddressLists=$Enabled}
}
#endregion