Skip to content

Commit d785644

Browse files
authored
Create Start-Join.ps1
1 parent 57b1abf commit d785644

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Scripts/Start-Join.ps1

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Param(
2+
[Parameter(Mandatory=$true,
3+
ValueFromPipeline=$true)]
4+
[String]
5+
$DomainName,
6+
7+
[Parameter(Mandatory=$true,
8+
ValueFromPipeline=$true)]
9+
[String]
10+
$ComputerName,
11+
12+
[Parameter(Mandatory=$true,
13+
ValueFromPipeline=$true)]
14+
[String]
15+
$UserName,
16+
17+
[Parameter(Mandatory=$true,
18+
ValueFromPipeline=$true)]
19+
[String]
20+
$Password
21+
)
22+
23+
$UserName = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($UserName))
24+
$Password = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Password))
25+
26+
$script = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("
27+
Write-Host `"Waiting 30s for Lite Touch to finish...`"
28+
29+
Sleep -Seconds 30
30+
31+
Write-Host `"Clearing Connections...`"
32+
33+
Start-Process -FilePath `"net.exe`" -ArgumentList `"use`", `"*`", `"/delete`", `"/y`" -Wait
34+
35+
Stop-Service -Name `"Remote Desktop Configuration`" -ErrorAction SilentlyContinue
36+
Stop-Service -Name `"Netlogon`" -ErrorAction SilentlyContinue
37+
Stop-Service -Name `"Workstation`" -ErrorAction SilentlyContinue
38+
39+
Start-Service -Name `"Workstation`" -ErrorAction SilentlyContinue
40+
Start-Service -Name `"Netlogon`" -ErrorAction SilentlyContinue
41+
Start-Service -Name `"Remote Desktop Configuration`" -ErrorAction SilentlyContinue
42+
43+
`$Credential = New-Object pscredential -ArgumentList ([pscustomobject]@{
44+
UserName = `"$UserName`"
45+
Password = (ConvertTo-SecureString -String `"$Password`" -AsPlainText -Force)[0]
46+
})
47+
48+
Write-Host `"Joining Domain...`"
49+
50+
if([System.Environment]::MachineName.ToLower() -eq `"$ComputerName`".ToLower()) {
51+
Add-Computer -Domain `"$DomainName`" -Credential `$Credential
52+
} else {
53+
Add-Computer -Domain `"$DomainName`" -Credential `$Credential -NewName `"$ComputerName`"
54+
}
55+
56+
Write-Host `"Done.`"
57+
58+
Restart-Computer
59+
"))
60+
61+
Start-Process -FilePath "powershell.exe" -ArgumentList "-encodedCommand", $script

0 commit comments

Comments
 (0)