From 7625f60e00b4b02f2ab6825a4d949dae52a0ffe6 Mon Sep 17 00:00:00 2001
From: Michael <74507178+mschwab82@users.noreply.github.com>
Date: Wed, 16 Feb 2022 23:33:59 +0100
Subject: [PATCH] Initial
---
01_Config/BGInfo.ps1 | 80 ++++++++
01_Config/Network.ps1 | 10 +
01_Config/SRV-WSUS-01/BGInfo-SRV-WSUS-01.ps1 | 80 ++++++++
01_Config/SRV-WSUS-01/Network-SRV-WSUS-01.ps1 | 10 +
.../SRV-WSUS-01/Unattend-SRV-WSUS-01.xml | 122 ++++++++++++
01_Config/SetupComplete.cmd | 3 +
01_Config/unattend.xml | 122 ++++++++++++
.../WIN-SRV-2016-DataCenter-EN-EVAL.iso.txt | 0
.../2016/SYSPREP/2016_SypPrep-GUI.vhdx.txt | 0
.../2016/SYSPREP/2016_SysPrep_CORE.vhdx.txt | 0
02_Sources/2016/WIM/boot.wim.txt | 0
02_Sources/2016/WIM/install.wim.txt | 0
...ndows Server 2016 SERVERDATACENTER.clg.txt | 0
Win2016_GUI.ps1 | 184 ++++++++++++++++++
14 files changed, 611 insertions(+)
create mode 100644 01_Config/BGInfo.ps1
create mode 100644 01_Config/Network.ps1
create mode 100644 01_Config/SRV-WSUS-01/BGInfo-SRV-WSUS-01.ps1
create mode 100644 01_Config/SRV-WSUS-01/Network-SRV-WSUS-01.ps1
create mode 100644 01_Config/SRV-WSUS-01/Unattend-SRV-WSUS-01.xml
create mode 100644 01_Config/SetupComplete.cmd
create mode 100644 01_Config/unattend.xml
create mode 100644 02_Sources/2016/ISO/WIN-SRV-2016-DataCenter-EN-EVAL.iso.txt
create mode 100644 02_Sources/2016/SYSPREP/2016_SypPrep-GUI.vhdx.txt
create mode 100644 02_Sources/2016/SYSPREP/2016_SysPrep_CORE.vhdx.txt
create mode 100644 02_Sources/2016/WIM/boot.wim.txt
create mode 100644 02_Sources/2016/WIM/install.wim.txt
create mode 100644 02_Sources/2016/WIM/install_Windows Server 2016 SERVERDATACENTER.clg.txt
create mode 100644 Win2016_GUI.ps1
diff --git a/01_Config/BGInfo.ps1 b/01_Config/BGInfo.ps1
new file mode 100644
index 0000000..da526cf
--- /dev/null
+++ b/01_Config/BGInfo.ps1
@@ -0,0 +1,80 @@
+<#
+.SYNOPSIS
+
+A script used to download, install and configure the latest BgInfo version on a Windows Server 2016 or 2019.
+
+.DESCRIPTION
+
+A script used to download, install and configure the latest BgInfo version (v4.27) on a Windows Server 2016 or 2019. The BgInfo folder will be created on the C: drive if the folder does not already exist.
+Then the latest BgInfo.zip file will be downloaded and extracted in the BgInfo folder. The LogonBgi.zip file which holds the preferred settings will also be downloaded and extracted to the BgInfo folder.
+After extraction both .zip files will be deleted. A registry key (regkey) to AutoStart the BgInfo tool in combination with the logon.bgi config file will be created. At the end of the script BgInfo will
+be started for the first time and the PowerShell window will be closed.
+
+.NOTES
+
+File Name: BgInfo_Automated_Windows_Server_2016_2019.ps1
+Created: 08/09/2019
+Last modified: 13/09/2019
+Author: Wim Matthyssen
+PowerShell: 5.1 or above
+Requires: -RunAsAdministrator
+OS: Windows Server 2016 and Windows Server 2019
+Version: 2.2
+Action: Change variables were needed to fit your needs
+Disclaimer: This script is provided "As Is" with no warranties.
+
+.EXAMPLE
+
+.\BgInfo_Automated_Windows_Server_2016_2019.ps1
+
+.LINK
+
+https://tinyurl.com/y3wmsh7o
+#>
+
+## Variables
+
+$bgInfoFolder = "C:\BgInfo"
+$bgInfoFolderContent = $bgInfoFolder + "\*"
+$itemType = "Directory"
+$bgInfoUrl = "https://download.sysinternals.com/files/BGInfo.zip"
+$bgInfoZip = "C:\BgInfo\BGInfo.zip"
+$bgInfoEula = "C:\BgInfo\Eula.txt"
+$logonBgiUrl = "https://tinyurl.com/yxlxbgun"
+$logonBgiZip = "C:\BgInfo\LogonBgi.zip"
+$bgInfoRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
+$bgInfoRegKey = "BgInfo"
+$bgInfoRegType = "String"
+$bgInfoRegKeyValue = "C:\BgInfo\Bginfo64.exe C:\BgInfo\logon.bgi /timer:0 /nolicprompt"
+$regKeyExists = (Get-Item $bgInfoRegPath -EA Ignore).Property -contains $bgInfoRegkey
+$writeEmptyLine = "`n"
+$writeSeperator = " - "
+$time = Get-Date -UFormat "%A %m/%d/%Y %R"
+$foregroundColor1 = "Yellow"
+$foregroundColor2 = "Red"
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
+
+## Create BgInfo Registry Key to AutoStart
+
+If ($regKeyExists -eq $True){Write-Host ($writeEmptyLine + "BgInfo regkey exists, script wil go on" + $writeSeperator + $time)`
+-foregroundcolor $foregroundColor2 $writeEmptyLine
+}Else{
+New-ItemProperty -Path $bgInfoRegPath -Name $bgInfoRegkey -PropertyType $bgInfoRegType -Value $bgInfoRegkeyValue
+Write-Host ($writeEmptyLine + "# BgInfo regkey added" + $writeSeperator + $time)`
+-foregroundcolor $foregroundColor1 $writeEmptyLine}
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
+
+## Run BgInfo
+
+C:\BgInfo\Bginfo64.exe C:\BgInfo\logon.bgi /timer:0 /nolicprompt
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
+
+## Exit PowerShell window 2 seconds after completion
+
+Start-Sleep 2
+stop-process -Id $PID
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
\ No newline at end of file
diff --git a/01_Config/Network.ps1 b/01_Config/Network.ps1
new file mode 100644
index 0000000..6155a21
--- /dev/null
+++ b/01_Config/Network.ps1
@@ -0,0 +1,10 @@
+# Networkconfiguration
+
+$ConfigAdapterName = Get-NetAdapter | where MacAddress -eq "1MACAddress"
+
+Rename-NetAdapter -Name $ConfigAdapterName.name -NewName "1NetworkAdapterName"
+Set-NetIPInterface -InterfaceIndex $ConfigAdapterName.ifIndex -Dhcp Disabled
+
+New-NetIPAddress -InterfaceIndex $ConfigAdapterName.ifIndex -IPAddress 1IPDomain -DefaultGateway 1DefaultGW -PrefixLength 24
+Set-DNSClientServerAddress -InterfaceIndex $ConfigAdapterName.ifIndex -ServerAddresses ("1DNSServer1","1DNSServer2")
+Set-DnsClientGlobalSetting -SuffixSearchList @("1DNSDomain")
\ No newline at end of file
diff --git a/01_Config/SRV-WSUS-01/BGInfo-SRV-WSUS-01.ps1 b/01_Config/SRV-WSUS-01/BGInfo-SRV-WSUS-01.ps1
new file mode 100644
index 0000000..da526cf
--- /dev/null
+++ b/01_Config/SRV-WSUS-01/BGInfo-SRV-WSUS-01.ps1
@@ -0,0 +1,80 @@
+<#
+.SYNOPSIS
+
+A script used to download, install and configure the latest BgInfo version on a Windows Server 2016 or 2019.
+
+.DESCRIPTION
+
+A script used to download, install and configure the latest BgInfo version (v4.27) on a Windows Server 2016 or 2019. The BgInfo folder will be created on the C: drive if the folder does not already exist.
+Then the latest BgInfo.zip file will be downloaded and extracted in the BgInfo folder. The LogonBgi.zip file which holds the preferred settings will also be downloaded and extracted to the BgInfo folder.
+After extraction both .zip files will be deleted. A registry key (regkey) to AutoStart the BgInfo tool in combination with the logon.bgi config file will be created. At the end of the script BgInfo will
+be started for the first time and the PowerShell window will be closed.
+
+.NOTES
+
+File Name: BgInfo_Automated_Windows_Server_2016_2019.ps1
+Created: 08/09/2019
+Last modified: 13/09/2019
+Author: Wim Matthyssen
+PowerShell: 5.1 or above
+Requires: -RunAsAdministrator
+OS: Windows Server 2016 and Windows Server 2019
+Version: 2.2
+Action: Change variables were needed to fit your needs
+Disclaimer: This script is provided "As Is" with no warranties.
+
+.EXAMPLE
+
+.\BgInfo_Automated_Windows_Server_2016_2019.ps1
+
+.LINK
+
+https://tinyurl.com/y3wmsh7o
+#>
+
+## Variables
+
+$bgInfoFolder = "C:\BgInfo"
+$bgInfoFolderContent = $bgInfoFolder + "\*"
+$itemType = "Directory"
+$bgInfoUrl = "https://download.sysinternals.com/files/BGInfo.zip"
+$bgInfoZip = "C:\BgInfo\BGInfo.zip"
+$bgInfoEula = "C:\BgInfo\Eula.txt"
+$logonBgiUrl = "https://tinyurl.com/yxlxbgun"
+$logonBgiZip = "C:\BgInfo\LogonBgi.zip"
+$bgInfoRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
+$bgInfoRegKey = "BgInfo"
+$bgInfoRegType = "String"
+$bgInfoRegKeyValue = "C:\BgInfo\Bginfo64.exe C:\BgInfo\logon.bgi /timer:0 /nolicprompt"
+$regKeyExists = (Get-Item $bgInfoRegPath -EA Ignore).Property -contains $bgInfoRegkey
+$writeEmptyLine = "`n"
+$writeSeperator = " - "
+$time = Get-Date -UFormat "%A %m/%d/%Y %R"
+$foregroundColor1 = "Yellow"
+$foregroundColor2 = "Red"
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
+
+## Create BgInfo Registry Key to AutoStart
+
+If ($regKeyExists -eq $True){Write-Host ($writeEmptyLine + "BgInfo regkey exists, script wil go on" + $writeSeperator + $time)`
+-foregroundcolor $foregroundColor2 $writeEmptyLine
+}Else{
+New-ItemProperty -Path $bgInfoRegPath -Name $bgInfoRegkey -PropertyType $bgInfoRegType -Value $bgInfoRegkeyValue
+Write-Host ($writeEmptyLine + "# BgInfo regkey added" + $writeSeperator + $time)`
+-foregroundcolor $foregroundColor1 $writeEmptyLine}
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
+
+## Run BgInfo
+
+C:\BgInfo\Bginfo64.exe C:\BgInfo\logon.bgi /timer:0 /nolicprompt
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
+
+## Exit PowerShell window 2 seconds after completion
+
+Start-Sleep 2
+stop-process -Id $PID
+
+##-------------------------------------------------------------------------------------------------------------------------------------------------------
\ No newline at end of file
diff --git a/01_Config/SRV-WSUS-01/Network-SRV-WSUS-01.ps1 b/01_Config/SRV-WSUS-01/Network-SRV-WSUS-01.ps1
new file mode 100644
index 0000000..f9525ff
--- /dev/null
+++ b/01_Config/SRV-WSUS-01/Network-SRV-WSUS-01.ps1
@@ -0,0 +1,10 @@
+# Networkconfiguration
+
+$ConfigAdapterName = Get-NetAdapter | where MacAddress -eq "00-15-5D-01-10-6D"
+
+Rename-NetAdapter -Name $ConfigAdapterName.name -NewName "Primary Adapter"
+Set-NetIPInterface -InterfaceIndex $ConfigAdapterName.ifIndex -Dhcp Disabled
+
+New-NetIPAddress -InterfaceIndex $ConfigAdapterName.ifIndex -IPAddress 192.168.10.15 -DefaultGateway 192.168.10.1 -PrefixLength 24
+Set-DNSClientServerAddress -InterfaceIndex $ConfigAdapterName.ifIndex -ServerAddresses ("192.168.10.11","192.168.10.10")
+Set-DnsClientGlobalSetting -SuffixSearchList @("schwab.local")
diff --git a/01_Config/SRV-WSUS-01/Unattend-SRV-WSUS-01.xml b/01_Config/SRV-WSUS-01/Unattend-SRV-WSUS-01.xml
new file mode 100644
index 0000000..12353dd
--- /dev/null
+++ b/01_Config/SRV-WSUS-01/Unattend-SRV-WSUS-01.xml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ eu-US
+ eu-US
+ eu-US
+ eu-US
+ de-CH
+
+
+
+ true
+ Local-Admin
+
+ true
+ true
+
+
+
+
+ 1
+
+
+
+
+ en-US
+ en-US
+ en-US
+ en-US
+ de-CH
+
+
+ true
+
+
+ 0
+
+
+ SRV-WSUS-01
+ TMJ3Y-NTRTM-FJYXT-T22BY-CWG3J
+
+
+ false
+
+
+
+
+ true
+ Remote Desktop
+ all
+
+
+
+
+ 0
+
+
+
+
+
+
+ MQBBAGQAbQBpAG4AUABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=
+ false
+
+ true
+ Local-Admin
+
+
+ false
+
+
+ true
+ true
+ true
+ true
+ 1
+ true
+ true
+
+
+
+
+
+ MQBBAGQAbQBpAG4AUABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=
+ false
+
+ Administrator (Local)
+ Administrators
+ Local-Admin
+
+
+
+
+ false
+ false
+ false
+
+ false
+ 0
+ false
+ 1
+ W. Europe Standard Time
+
+
+ de-CH
+ de-CH
+ de-CH
+ de-CH
+ de-CH
+
+
+
+
diff --git a/01_Config/SetupComplete.cmd b/01_Config/SetupComplete.cmd
new file mode 100644
index 0000000..f75b3c9
--- /dev/null
+++ b/01_Config/SetupComplete.cmd
@@ -0,0 +1,3 @@
+PowerShell "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force"
+PowerShell ". C:\Windows\Setup\Scripts\BGInfo.ps1"
+PowerShell ". C:\Windows\Setup\Scripts\Network.ps1"
\ No newline at end of file
diff --git a/01_Config/unattend.xml b/01_Config/unattend.xml
new file mode 100644
index 0000000..480cb29
--- /dev/null
+++ b/01_Config/unattend.xml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ eu-US
+ eu-US
+ eu-US
+ eu-US
+ de-CH
+
+
+
+ true
+ 1AdminAccount
+
+ true
+ true
+
+
+
+
+ 1
+
+
+
+
+ en-US
+ en-US
+ en-US
+ en-US
+ de-CH
+
+
+ true
+
+
+ 0
+
+
+ 1Name
+ 1ProductID
+
+
+ false
+
+
+
+
+ true
+ Remote Desktop
+ all
+
+
+
+
+ 0
+
+
+
+
+
+
+ MQBBAGQAbQBpAG4AUABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=
+ false
+
+ true
+ 1AdminAccount
+
+
+ false
+
+
+ true
+ true
+ true
+ true
+ 1
+ true
+ true
+
+
+
+
+
+ MQBBAGQAbQBpAG4AUABhAHMAcwB3AG8AcgBkAFAAYQBzAHMAdwBvAHIAZAA=
+ false
+
+ 1AdminDisplayName
+ Administrators
+ 1AdminAccount
+
+
+
+
+ false
+ false
+ false
+
+ false
+ 0
+ false
+ 1
+ W. Europe Standard Time
+
+
+ de-CH
+ de-CH
+ de-CH
+ de-CH
+ de-CH
+
+
+
+
diff --git a/02_Sources/2016/ISO/WIN-SRV-2016-DataCenter-EN-EVAL.iso.txt b/02_Sources/2016/ISO/WIN-SRV-2016-DataCenter-EN-EVAL.iso.txt
new file mode 100644
index 0000000..e69de29
diff --git a/02_Sources/2016/SYSPREP/2016_SypPrep-GUI.vhdx.txt b/02_Sources/2016/SYSPREP/2016_SypPrep-GUI.vhdx.txt
new file mode 100644
index 0000000..e69de29
diff --git a/02_Sources/2016/SYSPREP/2016_SysPrep_CORE.vhdx.txt b/02_Sources/2016/SYSPREP/2016_SysPrep_CORE.vhdx.txt
new file mode 100644
index 0000000..e69de29
diff --git a/02_Sources/2016/WIM/boot.wim.txt b/02_Sources/2016/WIM/boot.wim.txt
new file mode 100644
index 0000000..e69de29
diff --git a/02_Sources/2016/WIM/install.wim.txt b/02_Sources/2016/WIM/install.wim.txt
new file mode 100644
index 0000000..e69de29
diff --git a/02_Sources/2016/WIM/install_Windows Server 2016 SERVERDATACENTER.clg.txt b/02_Sources/2016/WIM/install_Windows Server 2016 SERVERDATACENTER.clg.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Win2016_GUI.ps1 b/Win2016_GUI.ps1
new file mode 100644
index 0000000..44e75af
--- /dev/null
+++ b/Win2016_GUI.ps1
@@ -0,0 +1,184 @@
+# -------------------------------------- Part 1 Start -------------------------------------- #
+
+ # Computername & VMName
+ $Name = "SRV-WSUS-01"
+
+ # CPU's
+ $CPUCount = 2
+
+ # VM Generation
+ $Generation = 2
+
+ # RAM
+ $RAMCount = 2GB
+ $RAMCountMin = 1GB
+ $RAMCountMax = 4GB
+
+ # DNS Domain Name
+ $DNSDomain = "schwab.local"
+
+ # IP Address
+ $IPDomain = "192.168.10.15"
+
+ # Default Gateway to be used
+ $DefaultGW = "192.168.10.1"
+
+ # DNS Server
+ $DNSServer1 = "192.168.10.11"
+ $DNSServer2 = "192.168.10.10"
+
+ # Hyper-V Switch Name
+ $SwitchNameDomain = "Private Net"
+
+ #Set the VM Domain access NIC name
+ $NetworkAdapterName = "Primary Adapter"
+
+ # Username & Password
+ $AdminAccount = "Local-Admin"
+ $AdminDisplayName = "Administrator (Local)"
+ $AdminPassword = "ABCD-1234"
+
+ # This ProductID is actually the AVMA key provided by MS
+ $ProductID = "TMJ3Y-NTRTM-FJYXT-T22BY-CWG3J"
+
+ # Where's the VM Default location? You can also specify it manually
+ $Path = Get-VMHost | select VirtualMachinePath -ExpandProperty VirtualMachinePath
+
+ # Where should I store the VM VHD?, you actually have nothing to do here unless you want a custom name on the VHD
+ $VHDPath = $Path + $Name + "\" + "Virtual Disks"
+ $VHDPathFile = $Path + $Name + "\" + "Virtual Disks" + "\" + $Name + ".vhdx"
+
+ # Where are the folders with prereq software ?
+ $StartupFolder = ".\01_Config\$Name"
+ $TemplateLocation = ".\02_Sources\2016\SYSPREP\2016_SypPrep-GUI.vhdx"
+ $UnattendLocation = ".\01_Config"
+
+# -------------------------------------- Part 1 Stop --------------------------------------- #
+
+function FN-Unattend
+{
+ Copy-Item $UnattendLocation\Unattend.xml $StartupFolder\Unattend-$Name.xml
+
+ $DefaultXML = $StartupFolder+"\Unattend-"+$Name+".xml"
+ $NewXML = $StartupFolder+"\Unattend-"+$Name+".xml"
+ $DefaultXML = Get-Content $DefaultXML
+ $DefaultXML | Foreach-Object {
+ $_ -replace '1AdminAccount', $AdminAccount `
+ -replace '1AdminDisplayName', $AdminDisplayName `
+ -replace '1Name', $Name `
+ -replace '1ProductID', $ProductID`
+ -replace '1AdminPassword', $AdminPassword `
+ } | Set-Content $NewXML
+}
+
+function FN-Network
+{
+ Copy-Item $UnattendLocation\Network.ps1 $StartupFolder\Network-$Name.ps1
+
+ $DefaultNetwork = $StartupFolder+ "\Network-"+$Name+".ps1"
+ $NewNetwork = $StartupFolder+ "\Network-"+$Name+".ps1"
+ $DefaultNetwork = Get-Content $DefaultNetwork
+ $DefaultNetwork | Foreach-Object {
+ $_ -replace '1MACAddress', $MACAddress `
+ -replace '1NetworkAdapterName', $NetworkAdapterName `
+ -replace '1IPDomain', $IPDomain `
+ -replace '1DefaultGW', $DefaultGW `
+ -replace '1DNSServer1', $DNSServer1 `
+ -replace '1DNSServer2', $DNSServer2 `
+ -replace '1DNSDomain', $DNSDomain `
+ } | Set-Content $NewNetwork
+}
+
+function FN-BGInfo
+{
+ Copy-Item $UnattendLocation\BGInfo.ps1 $StartupFolder\BGInfo-$Name.ps1
+
+ $NewBGInfo = $StartupFolder+ "\BGInfo-"+$Name+".ps1"
+
+}
+
+# -------------------------------------- Part 2 Start -------------------------------------- #
+
+
+# -- Check if VM exists -- #
+
+ $VMS = Get-VM
+ Foreach($VM in $VMS)
+ {
+ if ($Name -match $VM.Name)
+ {
+ write-host -ForegroundColor Red "Found VM With the same name!!!!!"
+ $Found=$True
+ }
+ }
+
+# -- Create the VM -- #
+
+ New-VM -Name $Name -Path $Path -MemoryStartupBytes $RAMCount -Generation 2 -NoVHD
+
+# -- Remove any auto generated adapters and add new ones with correct names for Consistent Device Naming -- #
+
+ Get-VMNetworkAdapter -VMName $Name | Remove-VMNetworkAdapter
+ Add-VMNetworkAdapter -VMName $Name -SwitchName $SwitchNameDomain -Name $NetworkAdapterName -DeviceNaming On
+
+# -- Start and stop VM to get mac address, then arm the new MAC address on the NIC itself -- #
+
+ start-vm $Name
+ sleep 5
+ stop-vm $Name -Force
+ sleep 5
+
+ $MACAddress = Get-VMNetworkAdapter -VMName $Name -Name $NetworkAdapterName|select MacAddress -ExpandProperty MacAddress
+ $MACAddress = ($MACAddress -replace '(..)','$1-').trim('-')
+ Get-VMNetworkAdapter -VMName $Name -Name $NetworkAdapterName|Set-VMNetworkAdapter -StaticMacAddress $MACAddress
+
+# -- Copy the template and add the disk on the VM. Also configure CPU and start - stop settings -- #
+
+ mkdir $VHDPath
+ Copy-item $TemplateLocation -Destination $VHDPathFile
+ Set-VM -Name $Name -ProcessorCount $CpuCount -AutomaticCheckpointsEnabled $false -AutomaticStartAction Start -AutomaticStopAction ShutDown -AutomaticStartDelay 5 -MemoryMinimumBytes $RAMCountMin -MemoryMaximumBytes $RAMCountMax
+ Add-VMHardDiskDrive -VMName $Name -ControllerType SCSI -Path $VHDPathFile
+
+# -- Set first boot device to the disk we attached -- #
+
+ $Drive = Get-VMHardDiskDrive -VMName $Name | where {$_.Path -eq "$VHDPathFile"}
+ Get-VMFirmware -VMName $Name | Set-VMFirmware -FirstBootDevice $Drive
+
+# -- Prepare the unattend.xml & SetupComplete.cmd file to send out, simply copy to a new file and replace values -- #
+
+ mkdir $StartupFolder
+
+ FN-Unattend
+
+ FN-Network
+
+ FN-BGInfo
+
+
+# -- Mount the new virtual machine VHD -- #
+
+ Mount-VHD -Path $VHDPathFile
+
+# -- Find the drive letter of the mounted VHD -- #
+
+ $VolumeDriveLetter = GET-DISKIMAGE $VHDPathFile | GET-DISK | GET-PARTITION |get-volume |?{$_.FileSystemLabel -ne "Recovery"}|select DriveLetter -ExpandProperty DriveLetter
+
+# -- Construct the drive letter of the mounted VHD Drive -- #
+
+ $DriveLetter = "$VolumeDriveLetter"+":"
+
+# -- Copy the unattend.xml to the drive -- #
+
+ Copy-Item $NewXML $DriveLetter\unattend.xml
+ Copy-Item $NewNetwork $DriveLetter\Windows\Setup\Scripts\Network.ps1
+ Copy-Item $NewBGInfo $DriveLetter\Windows\Setup\Scripts\BGInfo.ps1
+
+# -- Dismount the VHD -- #
+
+ Dismount-Vhd -Path $VHDPathFile
+
+# -- Fire up the VM -- #
+
+ Start-VM $Name
+
+# -------------------------------------- Part 2 Stop --------------------------------------- #
\ No newline at end of file