-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSet-NewDLName.ps1
120 lines (85 loc) · 3.85 KB
/
Set-NewDLName.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<#
.SYNOPSIS
This function add a character to the DL name if exchange hybrid is enabled (allows for the dynamic group creation.)
.DESCRIPTION
This function add a character to the DL name if exchange hybrid is enabled (allows for the dynamic group creation.)
.PARAMETER GlobalCatalogServer
The global catalog to make the query against.
.PARAMETER DN
The original DN of the object.
.PARAMETER DLName
The name of the DL from the original configuration.
.PARAMETER DLSamAccountName
The original DN of the object.
.PARAMETER adCredential
.OUTPUTS
None
.EXAMPLE
set-newDLName -dlConfiguration dlConfiguration -globalCatalogServer globalCatalogServer
#>
Function set-newDLName
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
[string]$globalCatalogServer,
[Parameter(Mandatory = $true)]
$dlName,
[Parameter(Mandatory = $true)]
$dlSAMAccountName,
[Parameter(Mandatory = $true)]
$DN,
[Parameter(Mandatory = $true)]
$adCredential,
[Parameter(Mandatory = $false)]
[ValidateSet("Basic","Negotiate")]
$activeDirectoryAuthenticationMethod="Negotiate"
)
#Output all parameters bound or unbound and their associated values.
write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)
#Declare function variables.
[string]$functionGroupName=$NULL #Holds the calculated name.
[string]$functionGroupSAMAccountName=$NULL #Holds the calculated sam account name.
[string]$functionMaxLength = 64
[string]$functionGroupNameCharacter = "!"
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN SET-NEWDLNAME"
Out-LogFile -string "********************************************************************************"
#Establish new names
if ($dlName.length -eq $functionMaxLength)
{
out-logfile -string "Group name is 64 characters - truncate single character to support rename."
[string]$functionGroupName = $dlName.substring(0,$functionMaxLength-1)+$functionGroupNameCharacter
}
else
{
[string]$functionGroupName = $dlname+$functionGroupNameCharacter
out-logfile -string "Group name does not exceed 64 characters - rename as normal."
}
[string]$functionGroupSAMAccountName = $dlSAMAccountName+"!"
out-logfile -string ("New group name = "+$functionGroupName)
out-logfile -string ("New group sam account name = "+$functionGroupSAMAccountName)
#Get the specific user using ad providers.
try
{
Out-LogFile -string "Set the AD group name."
set-adGroup -identity $dn -samAccountName $functionGroupSAMAccountName -server $globalCatalogServer -Credential $adCredential -authType $activeDirectoryAuthenticationMethod -errorAction STOP
}
catch
{
Out-LogFile -string $_ -isError:$TRUE
}
try
{
out-logfile -string "Setting the new group name.."
rename-adobject -identity $dn -newName $functionGroupName -server $globalCatalogServer -credential $adCredential -authType $activeDirectoryAuthenticationMethod -errorAction STOP
}
catch
{
Out-LogFile -string $_ -isError:$true
}
Out-LogFile -string "END Set-NewDLName"
Out-LogFile -string "********************************************************************************"
}