Sort of a Part II – This part was somewhat eluded to in the previous post, this script is run immediately after provisioning a toothless Hyper-V guest running Windows Server 2016.

Sequence of events:

  1. Provision VM guest:
    1. 12-16 GB memory
    2. 1 or 2 vCPU
    3. 1 Differencing Disk pointed to a VHD with sysprepped Windows Server 2016 (I’m too lazy and cheap to stand up a real VMM environment, and I don’t have the right hardware for it anyway)
    4. Two (2) SCSI disks, at 200 GB each, dynamic sized VHDX (lab environment only)
  2. Boot the VM guest
  3. Finish the OOBE process
  4. Edit the TXT script in GitHub (Gist item)
  5. Click RAW view, copy URL
  6. Restart (to invoke Hyper-V guest tools, and enable the guest clipboard)
  7. Open PowerShell console
  8. Type followed by the URL to the raw Gist file
  9. Press Enter

What it does:

  • Rename the VM
  • Assign a static IPv4 address and gateway
  • Initialize and format the 2 secondary disks at 64k units, with labels
  • Join to domain
  • Reboot
 invoked from BoxStarter to prepare a general Windows Server configuration
 other scripts follow on to this to create specific roles

 written by David Stein
 1. powershell console
 2. start the raw-view URL here)
 1. Machine has Windows Server 2012 R2 or 2016 installed
 2. Machine has 1 OS disk and 2 additional disks
 note: using hyper-v with differencing disk as disk[0]
 3. The additional disks are not online (vmguest default)
 note: using hyper-v with 2 scsi vhdx disks as disk[1] and disk[2]
 4. [global parameters] below are configured prior to running
 powershell start

# global parameters
$ServerName = "CM01"
$DomainName = "CONTOSO"
$OuPath = "OU=Servers,OU=Corp,DC=contoso,DC=com"
$DomainUser = "$DomainName\sccmadmin"
$IPv4Address = ""
$IPv4Mask = ""
$IPv4Gateway = ""
$IPv4DNS = ""

$ScriptVersion = "2016.12.19.01"

$Boxstarter.RebootOk = $true

write-host "Script Version $ScriptVersion" -ForegroundColor Green


write-output "info: configuring static ip address: $IPv4Address ..."
$wmi = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IpEnabled = 'true'"
if ($wmi -ne $null) {
  $wmi.EnableStatic($IPv4Address, $IPv4Mask)
  $wmi.SetGateways($IPv4Gateway, 1)
else {
  write-output "error: no active network adapter found"

$HostName = $($env:computername).ToUpper()
if ($HostName -ne $ServerName) {
  write-output "info: renaming host to $ServerName..."
  Rename-Computer -NewName $ServerName
  if (Test-PendingReboot) { Invoke-Reboot }
else {
  write-output "info: computer is already named $ServerName"

write-output "info: provisioning secondary disks..."
$disks = @("1=APPS","2=DATA")
foreach ($disk in $disks) {
  $diskset = $disk.Split("=")
  Get-Disk -Number $diskset[0] |
  New-Partition -AssignDriveLetter -UseMaximumSize |
  Format-Volume -FileSystem NTFS -NewFileSystemLabel $diskset[1] -AllocationUnitSize 65536 -Force -Confirm:$False
write-output "info: secondary disks have been provisioned."

write-output "info: checking domain join status..."
$Dom = $env:userdomain
if ($Dom -ne $DomainName) {
  write-output "info: joining computer to domain $DomainName..."
  Add-Computer -DomainName "$DomainName" -Credential $DomainUser -OUPath $OuPath
else {
  write-output "info: computer is already domain joined."

$sm = Get-ItemProperty -Path HKCU:\Software\Microsoft\ServerManager -Name DoNotOpenServerManagerAtLogon -ErrorAction SilentlyContinue
if ($sm -eq $null) {
  write-output "info: disabling server manager at startup..."
  New-ItemProperty -Path HKCU:\Software\Microsoft\ServerManager -Name DoNotOpenServerManagerAtLogon -PropertyType DWORD -Value "0x1" -Force


write-output "info: base configuration is finished!"

$Boxstarter.RebootOk = $False
Restart-Computer -Force

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s