forked from timmcmic/DLConversionV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet-NewDLName.ps1
104 lines (71 loc) · 3.05 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
<#
.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
)
#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.
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN SET-NEWDLNAME"
Out-LogFile -string "********************************************************************************"
#Establish new names
[string]$functionGroupName = $dlName+"!"
[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
}
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
}
catch
{
Out-LogFile -string $_ -isError:$true
}
Out-LogFile -string "END Set-NewDLName"
Out-LogFile -string "********************************************************************************"
}