@ -1,11 +1,17 @@
[ cmdletbinding ( DefaultParameterSetName = " RunWindowsUpdates " ) ] param (
[ Parameter ( ParameterSetName = " RunWindowsUpdates " ) ] [ switch ] $RunWindowsUpdates ,
[ Parameter ( Mandatory = $true , ParameterSetName = " SkipWindowsUpdates " ) ] [ switch ] $SkipWindowsUpdates
[ cmdletbinding ( ) ] Param (
[ switch ] $SkipWindowsUpdates
)
import-module $PSScriptRoot \ wintriallab-postinstall . psm1
$errorActionPreference = " Stop "
# Useful for debugging
$message = " Environment variables: `r `n `r `n "
foreach ( $var in ( Get-ChildItem env : \ ) ) {
$message + = " $( $var . Name ) = $( $var . Value ) `r `n "
}
Write-EventLogWrapper -message $message
Invoke-ScriptblockAndCatch -scriptBlock {
Write-EventLogWrapper " Starting the autounattend postinstall script "
Set-IdleDisplayPoweroffTime -seconds 0
@ -13,21 +19,30 @@ Invoke-ScriptblockAndCatch -scriptBlock {
Disable-HibernationFile
Enable-MicrosoftUpdate
# Need to reboot for some of these drivers to take
# Requires that the packer file attach the Guest VM driver disc, rather than upload it
# (Uploading it also gives problems when using WinRM - too big? - so this is a better solution anyway)
Install-VBoxAdditions -fromDisc
# Note that we need to reboot for some of these drivers to take
# AHHHH, PACKER_BUILDER_TYPE ISN'T AVAILABLE HERE BECAUSE IT'S INVOKED FROM THE WINDOWS INSTALLER. Hmmmmmm. Might have to do this later.
if ( $env:PACKER_BUILDER_TYPE -contains " virtualbox " ) {
# Requires that the packerfile attach the Guest VM driver disk, rather than upload it (the packer-windows way). Uploading it gives problems with WinRM for some reason.
Install-VBoxAdditions -fromDisc
}
elseif ( $env:PACKER_BUILDER_TYPE -contains " hyperv " ) {
Write-EventLogWrapper -message " Hyper-V builder detected, but we don't have a way to install its drivers yet "
}
else {
Write-EventLogWrapper -message " A builder called ' $env:PACKER_BUILDER_TYPE ' was detected, but we don't have a way to install its drivers yet "
}
# Required for Windows 10, not required for 81, not sure about other OSes
# Should probably happen after installing Guest VM drivers, in case installing the drivers would cause Windows to see the network as a new connection
Set-AllNetworksToPrivate
# Should probably happen after installing Guest VM drivers, in case installing the drivers would cause Windows to see the network as a new connection
Set-AllNetworksToPrivate
switch ( $PsCmdlet . ParameterSetName ) {
" RunWindowsUpdates " { $restartCommand = [ ScriptBlock ] :: Create ( " A:\win-updates.ps1 -PostUpdateExpression A:\enable-winrm.ps1 " ) }
" SkipWindowsUpdates " { $restartCommand = [ ScriptBlock ] :: Create ( " A:\enable-winrm.ps1 " ) }
default { throw " Not configured for this parameter set... " }
if ( $SkipWindowsUpdates ) {
$restartCommand = [ ScriptBlock ] :: Create ( " A:\enable-winrm.ps1 " ) }
}
else {
$restartCommand = [ ScriptBlock ] :: Create ( " A:\win-updates.ps1 -PostUpdateExpression A:\enable-winrm.ps1 " )
}
Set-RestartScheduledTask -RestartCommand $restartCommand | out-null
Restart-Computer -force
Restart-Computer -force
}