forked from bseltz-cohesity/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddActiveDirectory.ps1
77 lines (68 loc) · 2.79 KB
/
addActiveDirectory.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
### usage: ./addActiveDirectory.ps1 -cluster mycluster `
# -username myuser `
# -domain local `
# -adDomain mydomain.net `
# -adUsername [email protected] `
# -adPassword bosco `
# -adComputername mycluster `
# -adContainer US/IT/Servers
### process commandline arguments
[CmdletBinding()]
param (
[Parameter(Mandatory = $True)][string]$cluster, # cohesity cluster to connect to
[Parameter(Mandatory = $True)][string]$username, # cohesity username
[Parameter()][string]$domain = 'local', # user domain
[Parameter()][string]$adDomain = $null, # AD domain to join
[Parameter()][string]$adUsername = $null, # AD User to join domain
[Parameter()][string]$adPassword = $null, # AD password to join domain
[Parameter()][string]$adComputername = $null, # Computer account name for cluster
[Parameter()][string]$adContainer = 'Computers', # AD Container Path for computer account
[Parameter()][string]$adNetbiosname = $null, # AD Container Path for computer account
[Parameter()][switch]$useExistingComputerAccount, # Overwrite existing computer account
[Parameter()][string]$configFile = $null # Optional config file to provide parameters
)
# read config file if specified
if($configFile -and (Test-Path $configFile -PathType Leaf)){
. $configFile
}
# confirm all required parameters
if($null -eq $adDomain -or $null -eq $adUsername -or $null -eq $adPassword -or $null -eq $adComputername){
write-host "The following parameters are required:
-adDomain
-adUsername
-adPassword
-adComputername" -ForegroundColor Yellow
exit
}
# source the cohesity-api helper code
. $(Join-Path -Path $PSScriptRoot -ChildPath cohesity-api.ps1)
# authenticate
apiauth -vip $cluster -username $username -domain $domain
# define adParameters object
$adParameters = @{
"domainName" = $adDomain;
"userName" = $adUsername;
"password" = $adPassword;
"preferredDomainControllers" = @(
@{
"domainName" = $adDomain
}
);
"machineAccounts" = @(
$adComputername
);
"overwriteExistingAccounts" = $false;
"userIdMapping" = @{};
"ouName" = $adContainer
}
# add optional NETBIOS name
if($adNetbiosname){
$adParameters['workgroup'] = $adNetbiosname
}
# overwrite existing account
if($useExistingComputerAccount){
$adParameters.overwriteExistingAccounts = $True
}
# join AD
"Joining $adDomain..."
$null = api post activeDirectory $adParameters