diff --git a/scripts/ADDS/payload/Apply-OVFProperties.ps1 b/scripts/ADDS/payload/Apply-OVFProperties.ps1 index 0fadc11..f189b7f 100644 --- a/scripts/ADDS/payload/Apply-OVFProperties.ps1 +++ b/scripts/ADDS/payload/Apply-OVFProperties.ps1 @@ -77,6 +77,12 @@ If ($MissingProperties.Length -gt 0) { # Set hostname and description If ($Env:ComputerName -ne $ovfPropertyValues['guestinfo.hostname']) { + $NewToastSplat = @{ + Title = 'OVF Properties' + Text = 'Configuring hostname and description...' + } + New-ToastNotification @NewToastSplat + $RenameComputerSplat = @{ NewName = $ovfPropertyValues['guestinfo.hostname'] Force = $True @@ -98,6 +104,12 @@ If ($Env:ComputerName -ne $ovfPropertyValues['guestinfo.hostname']) { # Configure network interface If ((Get-WmiObject -Class 'Win32_NetworkAdapterConfiguration').IPAddress -NotContains $ovfPropertyValues['guestinfo.ipaddress']) { + $NewToastSplat = @{ + Title = 'OVF Properties' + Text = 'Configuring network...' + } + New-ToastNotification @NewToastSplat + $NewNetIPAddressSplat = @{ InterfaceAlias = (Get-NetAdapter).Name AddressFamily = 'IPv4' @@ -152,6 +164,12 @@ If ((Get-WmiObject -Class 'Win32_NetworkAdapterConfiguration').IPAddress -NotCon # Promote to Domain Controller If ((4,5) -NotContains (Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole) { + $NewToastSplat = @{ + Title = 'OVF Properties' + Text = 'Configuring local administrator password...' + } + New-ToastNotification @NewToastSplat + # Change password of built-in Administrator $BuiltinAdministrator = (Get-LocalUser | Where-Object {$_.SID -match '-500'}) $ConvertToSecureStringSplat = @{ @@ -170,6 +188,12 @@ If ((4,5) -NotContains (Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole) } Set-LocalUser @SetLocalUserSplat + $NewToastSplat = @{ + Title = 'OVF Properties' + Text = 'Promoting to Domain Controller...' + } + New-ToastNotification @NewToastSplat + $ResolveDNSNameSplat = @{ Name = "_ldap._tcp.dc._msdcs.$($ovfPropertyValues['addsconfig.domainname'])" ErrorAction = 'SilentlyContinue' @@ -228,6 +252,12 @@ If ((4,5) -NotContains (Get-WmiObject -Class 'Win32_ComputerSystem').DomainRole) } # Wait for Active Directory to become available +$NewToastSplat = @{ + Title = 'OVF Properties' + Text = 'Waiting for Active Directory services...' +} +New-ToastNotification @NewToastSplat + $Timestamp, $TimeoutMinutes = (Get-Date), 15 Do { If ($Timestamp.AddMinutes($TimeoutMinutes) -lt (Get-Date)) { @@ -258,6 +288,12 @@ $GetItemSplat = @{ } Get-Item @GetItemSplat | ForEach-Object { Try { + $NewToastSplat = @{ + Title = 'OVF Properties' + Text = "Running script: '$($_.FullName)'" + } + New-ToastNotification @NewToastSplat + $WriteEventLogSplat = @{ LogName = 'Application' Source = 'OVF-Properties' @@ -280,6 +316,12 @@ Get-Item @GetItemSplat | ForEach-Object { } } +$NewToastSplat = @{ + Title = 'OVF Properties' + Text = "Sequence finished; ready for use!" +} +New-ToastNotification @NewToastSplat + $WriteEventLogSplat = @{ LogName = 'Application' Source = 'OVF-Properties' @@ -289,3 +331,26 @@ $WriteEventLogSplat = @{ } Write-EventLog @WriteEventLogSplat & schtasks.exe /Change /TN 'OVF-Properties' /DISABLE + +Function New-ToastNotification () { + Param( + [Parameter] + [string]$Stream = 'OVF Properties', + [Parameter(Mandatory)] + [string]$Title, + [Parameter(Mandatory)] + [string]$Text + ) + + $Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) + + $XML = [xml]$Template.GetXml() + $XML.SelectSingleNode("toast/visual/binding/text[@id='1']").InnerText = $Title + $XML.SelectSingleNode("toast/visual/binding/text[@id='2']").InnerText = $Text + + $SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument + $SerializedXml.LoadXml($XML.OuterXml) + + $Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($Stream) + $Notifier.Show([Windows.UI.Notifications.ToastNotification]::new($SerializedXml)) +} \ No newline at end of file