Payloadscripts act on 'deployment.type'
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Danny Bessems 2021-01-27 12:12:44 +01:00
parent bd0423e701
commit 09f36ea66a
13 changed files with 55 additions and 33 deletions

View File

@ -30,22 +30,44 @@ foreach ($ovfProperty in $ovfProperties) {
}
# Check for mandatory values
If (!($ovfPropertyValues['guestinfo.hostname'] -and
$ovfPropertyValues['guestinfo.ipaddress'] -and
$ovfPropertyValues['guestinfo.dnsserver'] -and
$ovfPropertyValues['guestinfo.prefixlength'] -and
$ovfPropertyValues['guestinfo.gateway'] -and
$ovfPropertyValues['addsconfig.domainname'] -and
$ovfPropertyValues['addsconfig.netbiosname'] -and
$ovfPropertyValues['addsconfig.administratorpw'] -and
$ovfPropertyValues['addsconfig.safemodepw'])) {
Switch ($ovfPropertyValues['deployment.type']) {
'primary' {
$MandatoryProperties, $MissingProperties = @('guestinfo.hostname', 'guestinfo.ipaddress', 'guestinfo.prefixlength', 'guestinfo.gateway', 'addsconfig.domainname', 'addsconfig.netbiosname', 'addsconfig.administratorpw', 'addsconfig.safemodepw', 'addsconfig.ntpserver'), @()
}
'secondary' {
$MandatoryProperties, $MissingProperties = @('guestinfo.hostname', 'guestinfo.ipaddress', 'guestinfo.prefixlength', 'guestinfo.dnsserver', 'guestinfo.gateway', 'addsconfig.domainname', 'addsconfig.netbiosname', 'addsconfig.administratorpw', 'addsconfig.safemodepw', 'dhcpconfig.startip', 'dhcpconfig.endip', 'dhcpconfig.subnetmask', 'dhcpconfig.gateway', 'dhcpconfig.leaseduration'), @()
}
'standalone' {
$MandatoryProperties, $MissingProperties = @('guestinfo.hostname', 'guestinfo.ipaddress', 'guestinfo.prefixlength', 'guestinfo.gateway', 'addsconfig.domainname', 'addsconfig.netbiosname', 'addsconfig.administratorpw', 'addsconfig.safemodepw', 'addsconfig.ntpserver', 'dhcpconfig.startip', 'dhcpconfig.endip', 'dhcpconfig.subnetmask', 'dhcpconfig.gateway', 'dhcpconfig.leaseduration'), @()
}
default {
# Mandatory values missing, cannot provision.
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
EntryType = 'Error'
EventID = 66
Message = 'Mandatory values missing, cannot provision.'
Message = "Unexpected or no value set for property 'deployment.type', cannot provision."
}
Write-EventLog @WriteEventLogSplat
& schtasks.exe /Change /TN 'OVF-Properties' /DISABLE
Stop-Computer -Force
Exit
}
}
ForEach ($Property in $MandatoryProperties) {
If (!$ovfPropertyValues[$Property]) {
$MissingProperties += $Property
}
}
If ($MissingProperties.Length -gt 0) {
# Mandatory values missing, cannot provision.
$WriteEventLogSplat = @{
LogName = 'Application'
Source = 'OVF-Properties'
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

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', ".csv")
}

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', ".csv")
}

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', ".csv")
}

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$PSDrive = Get-PSDrive -Name 'AD'
If ([boolean]$PSDrive -eq $False) {
$NewPSDriveSplat = @{

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', '.yml')
Raw = $true

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on secondary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 4) {
# Only executed on secondary or standalone Domain Controller
If (@('secondary','standalone') -contains $Parameter['deployment.type']) {
$AddDhcpServerv4ScopeSplat = @{
Name = 'Default DHCP scope'
StartRange = [ipaddress]$Parameter['dhcpconfig.startip']

View File

@ -5,7 +5,7 @@ Param(
)
# Only executed on secondary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 4) {
If ($Parameter['deployment.type'] -eq 'secondary') {
# Wait for secondary DHCP server to be registered in DNS
$Timestamp, $TimeoutMinutes = (Get-Date), 5
Do {

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on secondary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 4) {
# Only executed on secondary or standalone Domain Controller
If (@('secondary','standalone') -contains $Parameter['deployment.type']) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', '.yml')
Raw = $True

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', '.yml')
Raw = $True

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$NewPSSessionSplat = @{
ComputerName = $Parameter['guestinfo.hostname']
Credential = New-Object System.Management.Automation.PSCredential(

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$PSDrive = Get-PSDrive -Name 'AD'
If ([boolean]$PSDrive -eq $False) {
$NewPSDriveSplat = @{

View File

@ -4,8 +4,8 @@ Param(
[hashtable]$Parameter
)
# Only executed on primary Domain Controller
If ((Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole -eq 5) {
# Only executed on primary or standalone Domain Controller
If (@('primary','standalone') -contains $Parameter['deployment.type']) {
$GetContentSplat = @{
Path = "$($PSScriptRoot)\$($MyInvocation.MyCommand)".Replace('.ps1', ".yml")
Raw = $True