-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStart-Join.ps1
More file actions
73 lines (53 loc) · 2.11 KB
/
Start-Join.ps1
File metadata and controls
73 lines (53 loc) · 2.11 KB
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
Param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[String]
$DomainName,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[String]
$ComputerName,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[String]
$UserName,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[String]
$Password
)
$UserName = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($UserName))
$Password = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Password))
foreach ($char in "``", "$", "`"") {
$Password = $Password.Replace($char, "``$($char)")
}
$Script = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("
Write-Host `"Waiting for Lite Touch to finish...`"
`$BDDRunning = `$true
while (`$BDDRunning) {
Start-Sleep -Milliseconds 500
`$BDDRunning = (Get-Process -Name BDDRun -ErrorAction SilentlyContinue).Count -gt 0
}
Write-Host `"Clearing Connections...`"
Start-Process -FilePath `"net.exe`" -ArgumentList `"use`", `"*`", `"/delete`", `"/y`" -Wait
Stop-Service -Name `"Remote Desktop Configuration`" -ErrorAction SilentlyContinue
Stop-Service -Name `"Netlogon`" -ErrorAction SilentlyContinue
Stop-Service -Name `"Workstation`" -ErrorAction SilentlyContinue
Start-Service -Name `"Workstation`" -ErrorAction SilentlyContinue
Start-Service -Name `"Netlogon`" -ErrorAction SilentlyContinue
Start-Service -Name `"Remote Desktop Configuration`" -ErrorAction SilentlyContinue
`$Credential = New-Object pscredential -ArgumentList ([pscustomobject]@{
UserName = `"$UserName`"
Password = (ConvertTo-SecureString -String `"$Password`" -AsPlainText -Force)[0]
})
Write-Host `"Joining Domain...`"
if([System.Environment]::MachineName.ToLower() -eq `"$ComputerName`".ToLower()) {
Add-Computer -Domain `"$DomainName`" -Credential `$Credential
} else {
Add-Computer -Domain `"$DomainName`" -Credential `$Credential -NewName `"$ComputerName`"
}
Start-Sleep -Seconds 5
Write-Host `"Done.`"
Restart-Computer
"))
Start-Process -FilePath "powershell.exe" -ArgumentList "-encodedCommand", $Script