Add yamllint;Replay downstream changes
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Danny Bessems 2021-04-09 11:43:42 +02:00
parent 8f54a61482
commit 34e14e721f
3 changed files with 28 additions and 18 deletions

View File

@ -19,6 +19,8 @@ steps:
sed -i -e "s/<<img-password>>/$${WINRM_PASSWORD}/g" \
packer/preseed/Server2019/Autounattend.xml \
packer/preseed/Server2019/Sysprep_Unattend.xml
- |
yamllint -d "{extends: relaxed, rules: {line-length: disable}}" scripts
- |
packer validate \
-var-file=packer/variables.vsphere.json \

View File

@ -4,4 +4,4 @@ Param(
)
# Create scheduled task
& schtasks.exe /Create /TN 'OVF-Properties' /SC ONSTART /RU SYSTEM /TR "powershell.exe -file C:\Payload\Apply-OVFProperties.ps1"
& schtasks.exe /Create /TN 'FirstBoot' /SC ONSTART /RU SYSTEM /TR "powershell.exe -file C:\Payload\Apply-FirstBootConfig.ps1"

View File

@ -3,18 +3,23 @@ Param(
# No parameters
)
$SetLocationSplat = @{
Path = $PSScriptRoot
}
Set-Location @SetLocationSplat
$NewEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
ErrorAction = 'SilentlyContinue'
}
New-EventLog @NewEventLogSplat
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
EntryType = 'Information'
EventID = 1
Message = 'OVF-Properties sequence initiated'
Message = "FirstBoot sequence initiated [working directory: '$PWD']"
}
Write-EventLog @WriteEventLogSplat
@ -40,13 +45,13 @@ Switch ($ovfPropertyValues['deployment.type']) {
# Mandatory values missing, cannot provision.
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
EntryType = 'Error'
EventID = 66
Message = "Unexpected or no value set for property 'deployment.type', cannot provision."
}
Write-EventLog @WriteEventLogSplat
& schtasks.exe /Change /TN 'OVF-Properties' /DISABLE
& schtasks.exe /Change /TN 'FirstBoot' /DISABLE
Stop-Computer -Force
Exit
}
@ -60,13 +65,13 @@ If ($MissingProperties.Length -gt 0) {
# Mandatory values missing, cannot provision.
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
EntryType = 'Error'
EventID = 66
Message = "Missing values for mandatory properties $(($MissingProperties | ForEach-Object {"'{0}'" -f $_}) -join ', '), cannot provision."
}
Write-EventLog @WriteEventLogSplat
& schtasks.exe /Change /TN 'OVF-Properties' /DISABLE
& schtasks.exe /Change /TN 'FirstBoot' /DISABLE
Stop-Computer -Force
Exit
}
@ -109,7 +114,7 @@ If ((Get-WmiObject -Class 'Win32_NetworkAdapterConfiguration').IPAddress -NotCon
If ($Timestamp.AddMinutes($TimeoutMinutes) -lt (Get-Date)) {
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
EntryType = 'Warning'
EventID = 13
Message = "Timeout after $($TimeoutMinutes) minutes waiting for network connection to become available."
@ -195,25 +200,28 @@ Switch ($ovfPropertyValues['deployment.type']) {
$GetItemSplat = @{
Path = "$($PSScriptRoot)\Scripts\*.ps1"
}
Get-Item @GetItemSplat | ForEach-Object {
ForEach ($Script in (Get-Item @GetItemSplat)) {
Try {
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
EntryType = 'Information'
EventID = 4
Message = "Running script: '$($_.FullName)'"
Message = "Running script: '$($Script.FullName)'"
}
Write-EventLog @WriteEventLogSplat
& $_.FullName -Parameter $ovfPropertyValues
& $Script.FullName -Parameter $ovfPropertyValues
}
Catch {
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
EntryType = 'Error'
EventID = 66
Message = $_.Exception.Message
Message = @"
Error occurred while executing script '$($Script.Name)':
$($_.Exception.Message)
"@
}
Write-EventLog @WriteEventLogSplat
}
@ -221,10 +229,10 @@ Get-Item @GetItemSplat | ForEach-Object {
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
Source = 'FirstBoot'
EntryType = 'Information'
EventID = 42
Message = 'OVF-Properties sequence applied and finished'
Message = 'FirstBoot sequence applied and finished'
}
Write-EventLog @WriteEventLogSplat
& schtasks.exe /Change /TN 'OVF-Properties' /DISABLE
& schtasks.exe /Change /TN 'FirstBoot' /DISABLE