-
Notifications
You must be signed in to change notification settings - Fork 0
/
addToDomain.ps1
44 lines (36 loc) · 1.4 KB
/
addToDomain.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
function Create-SupportFile {
$createFile = @'
$domain = "contoso.local"
$password = "password" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\da_contoso1"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential
echo "hello"| Out-File C:\Users\oaktree\Desktop\test.txt
remove-item $env:USERPROFILE\Desktop\joinToDomain.ps1
Unregister-ScheduledJob AddComputerToDomain
Restart-Computer AddComputerToDomain
'@
$createFile | out-file "$env:USERPROFILE\Desktop\joinToDomain.ps1"
}
function Convert-JoinDomain {
<#
.Description
Script to change the computer name of a host and add to a domain
.PARAMETER NewComputername
The new computername for the host.
.EXAMPLE
Convert-JoinDomain -NewComputerName WKSTN-2810
#>
Param (
[Parameter(Position = 0, Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[String]
$NewComputerName
)
$options = New-ScheduledJobOption -RunElevated -ContinueIfGoingOnBattery -StartIfOnBattery
$AtStartup = New-JobTrigger -Atstartup
Create-SupportFile
Register-ScheduledJob -Trigger $AtStartup $env:USERPROFILE\Desktop\joinToDomain.ps1 -name AddComputerToDomain -ScheduledJobOption $options
Rename-Computer -newname $NewComputerName
Restart-Computer -Force
}