This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSetup.ps1
53 lines (44 loc) · 1.57 KB
/
Setup.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
param(
[string]$Organization = "",
[string]$Owner = "",
[switch]$SkipRandomPassword,
[String]$Version
)
Push-Location $PSScriptRoot
. ./AutomationHelpers.ps1
. ./ProvisionVM.ps1
function Write-Log
{
Param (
[Parameter(Mandatory = $True, Position = 1)][string]$Message,
[string]$LogFile = "C:\provision\log.log"
)
$LogDir = (split-path $LogFile -parent)
If ((Test-Path $LogDir) -ne $True)
{
New-Item -Path $LogDir -ItemType Directory -Force
}
$msg = "{0} {1}" -f (Get-Date -Format o), $Message
Add-Content -Path $LogFile -Value $msg -Encoding 'UTF8'
Write-Host $msg
}
try {
Validate-OSVersion
Check-Dependencies
Set-RegKeys
# create the scheduled task to run second script here!
$Sta = Create-VMPrepTaskAction -Organization $Organization -Owner $Owner
if($SkipRandomPassword) {
$Sta = Create-VMPrepTaskAction -Organization $Organization -Owner $Owner -SkipRandomPassword
}
$STPrin = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
$Stt = New-ScheduledTaskTrigger -AtStartup
Register-ScheduledTask BoshCompleteVMPrep -Action $Sta -Trigger $Stt -Principal $STPrin -Description "Bosh Stemcell Automation task to complete the vm preparation"
Write-Log "Successfully registered the Bosh Stemcell Automation scheduled task"
ProvisionVM -Version $Version
} catch [Exception] {
Write-Log "Failed to install Bosh dependencies. See 'c:\provision\log.log' for more info."
DeleteScheduledTask
Exit 1
}
Pop-Location