Skip to content

Commit

Permalink
Bug Fix in Windows PE autopowershell launch
Browse files Browse the repository at this point in the history
Swapped the ' (quote) to the correct position
  • Loading branch information
doctorscripto committed Feb 29, 2016
1 parent e514748 commit e1f8402
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 84 deletions.
125 changes: 110 additions & 15 deletions DeployImage.psm1
@@ -1,3 +1,79 @@
function Convert-WIMtoVHD
{
[CmdletBinding()]
Param(
# Size of the VHD file
#
$Size=20GB,
# Obtain the default location of
# Virtual HardDisks in Hyper-V
#
$VHDPath='.\',
# Location of the WindowsImage (WIM)
# File to convert to VHD
#
$Wimfile='C:\Windows7\Install.wim',
# In the case of a single partition setup like
# USB Key or simple VHD SystemDrive and OSDrive
# Will be the same Letter
#
# Drive Letter being assigned to Boot Drive
#
$OSDrive='L',
# Netbios name of computer and VMName
#
$VM='Contoso-Win7',
# Index of Image in WIM file
#
$Index=1

)

If ($Vhdpath -eq '.\' -and (Get-Command Get-vmhost).count -ge 1)
{
$VHDPath=(Get-VMHost).VirtualHardDiskPath
}

# Define VHD filename
#
$VHD="$VhdPath\$VM.vhd"

If ((Test-Path $VHD) -ne $false)
{
Return $NULL
}
Else
{
# Create a new VHD
#
$Result=New-VHD -Path $Vhd -SizeBytes $Size -Dynamic

# Mount the VHD and identify it's Disk Object
#
$Result=Mount-VHD -Path $vhd
$Disk=Get-Vhd -Path $Vhd | Get-Disk

# Create a new Partition Structure of style
# MBR, Format and Partition System and OSDrive
#
New-PartitionStructure -Disk $disk -MBR -BootDrive $OSDrive -OSDrive $OsDrive

# Expand the Windows Image for Nano Server to the OSDrive
#
Expand-WindowsImage –imagepath "$wimfile" –index $Index –ApplyPath "$OSDrive`:\"

# Send the Boot files to the Disk Structure
#
Send-BootCode -BootDrive $OSDrive -OSDrive $OSDrive
# Dismount the Completed VHD
#
Dismount-VHD $VHD
# Return path of VHD
#
Return $VHD
}
}

Function Copy-WithProgress
{
[CmdletBinding()]
Expand Down Expand Up @@ -93,6 +169,7 @@ Function Remove-DriveLetter
until ($Status -eq $NULL)
}


<#
.Synopsis
Identifies if the Operating System is 32bit or 64bit
Expand Down Expand Up @@ -248,34 +325,34 @@ function New-PartitionStructure

if ($MBR)
{
Initialize-Disk -Number $Disk.Number -PartitionStyle MBR -ErrorAction SilentlyContinue
$Result=Initialize-Disk -Number $Disk.Number -PartitionStyle MBR -ErrorAction SilentlyContinue

if ($USB)
{
$Partition=New-Partition -DiskNumber $Disk.Number -DriveLetter $OSDrive -UseMaximumSize -IsActive
Format-Volume -Partition $Partition -FileSystem FAT32 -NewFileSystemLabel 'Windows'
$Result=Format-Volume -Partition $Partition -FileSystem FAT32 -NewFileSystemLabel 'Windows'
}
else
{
$Partition=New-Partition -DiskNumber $Disk.Number -DriveLetter $OSDrive -UseMaximumSize -IsActive
Format-Volume -Partition $Partition -FileSystem NTFS -NewFileSystemLabel 'Windows'
$Result=Format-Volume -Partition $Partition -FileSystem NTFS -NewFileSystemLabel 'Windows'
}

}
Else
{
Initialize-Disk -Number $Disk.Number -PartitionStyle GPT
$Result=Initialize-Disk -Number $Disk.Number -PartitionStyle GPT

$Partition=New-Partition -DiskNumber $Disk.Number -Size 128MB ; # Create Microsoft Basic Partition
Format-Volume -Partition $Partition -FileSystem Fat32 -NewFileSystemLabel 'MSR'
Set-Partition -DiskNumber $Disk.Number -PartitionNumber $Partition.PartitionNumber -GptType '{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}'
$Result=Format-Volume -Partition $Partition -FileSystem Fat32 -NewFileSystemLabel 'MSR'
$Result=Set-Partition -DiskNumber $Disk.Number -PartitionNumber $Partition.PartitionNumber -GptType '{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}'

$Partition=New-Partition -DiskNumber $Disk.Number -Size 300MB -DriveLetter $BootDrive ; # Create Microsoft Basic Partition and Set System as bootable
Format-Volume -Partition $Partition -FileSystem Fat32 -NewFileSystemLabel 'Boot'
Set-Partition -DiskNumber $Disk.Number -PartitionNumber $Partition.PartitionNumber
$Result=Format-Volume -Partition $Partition -FileSystem Fat32 -NewFileSystemLabel 'Boot'
$Result=Set-Partition -DiskNumber $Disk.Number -PartitionNumber $Partition.PartitionNumber

$Partition=New-Partition -DiskNumber $Disk.Number -DriveLetter $OSDrive -UseMaximumSize ; # Take remaining Disk space for Operating System
Format-Volume -Partition $Partition -FileSystem NTFS -NewFileSystemLabel 'Windows'
$Result=Format-Volume -Partition $Partition -FileSystem NTFS -NewFileSystemLabel 'Windows'
}

}
Expand Down Expand Up @@ -404,7 +481,11 @@ function New-UnattendXMLContent
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=10)]
[string]$OfflineBlob
[string]$OfflineBlob,
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=11)]
[switch]$SkipOOBE

)

Expand Down Expand Up @@ -486,19 +567,29 @@ $UnattendXML=$UnattendXML+@"
</AutoLogon>
<RegisteredOrganization>$Organization</RegisteredOrganization>
<RegisteredOwner>$Owner</RegisteredOwner>
"@

If ($SkipOOBE)
{
$UnattendXML=$UnattendXML+@"
<OOBE>
<HideEULAPage>true</HideEULAPage>
<-- <SkipMachineOOBE>true</SkipMachineOOBE> -->
<SkipMachineOOBE>true</SkipMachineOOBE>
</OOBE>
</component>
"@
}

$UnattendXML=$UnattendXML+@"
</settings>
"@

If ($OfflineBlob)
{
$UnattendXML=$UnattendXML+@"
<settings pass="offlineServicing">
<settings pass="offlineServicing">
<component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OfflineIdentification>
<Provisioning>
Expand Down Expand Up @@ -565,14 +656,18 @@ function Send-BootCode
[switch]$USB

)
$oldpref=$ErrorActionPreference
$ErrorActionPreference='SilentlyContinue'

if ($USB)
{
& "$($env:windir)\system32\bootsect.exe" /nt60 "$OSDrive`:"
& "$($env:windir)\system32\bootsect.exe" /nt60 "$OSDrive`:" > NULL
}
else
{
& "$($env:windir)\system32\bcdboot" "$OSDrive`:\Windows" /s "$BootDrive`:" /f ALL
& "$($env:windir)\system32\bcdboot" "$OSDrive`:\Windows" /s "$BootDrive`:" /f ALL > NULL
}
$ErrorActionPreference=$oldpref
}

function New-NanoServerWIM
Expand Down Expand Up @@ -806,7 +901,7 @@ Set-ExecutionPolicy -executionpolicy Bypass
$USBDisk=(Get-Disk | Where-Object { $_.BusType -eq 'USB' -and '$_.IsActive' })
$DriveLetter=($USBDisk | Get-Partition).DriveLetter
Set-Location ($DriveLetter+':\DeployImage\')
Import-Module ($DriveLetter+':\DeployImage\DeployImage.Psd1)'
Import-Module ($DriveLetter+':\DeployImage\DeployImage.Psd1')
'@

# Carriage Return (Ascii13) and Linefeed (Ascii10)
Expand Down
18 changes: 14 additions & 4 deletions DeployNanoServerPhysical.ps1
Expand Up @@ -4,13 +4,23 @@
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$WinPEMedia
$WinPEMedia,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
$Computername,
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=2)]
$Bootdrive='Y',
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=3)]
$OSDrive='Z'
)


$Wimfile=$WinPeMedia+':\Nanotemp\Nanocustom.wim'
$BootDrive='Y'
$OSDrive='Z'

$Disk=Get-AttachedDisk
$DriverPath=$WinPEMedia+':\Drivers'
Expand All @@ -19,7 +29,7 @@ New-PartitionStructure -Disk $disk -BootDrive $BootDrive -OSDrive $OsDrive
Expand-WindowsImage –imagepath "$wimfile" –index 1 –ApplyPath "$OSDrive`:\"

$Unattendfile='C:\Foo\Unattend.xml'
$Content=New-UnattendXMLContent -computername NanoServer1 -TimeZone 'Eastern Standard Time'
$Content=New-UnattendXMLContent -computername $Computername -TimeZone 'Eastern Standard Time'
Add-Content -path $Unattendfile -value $Content
Copy-Item $UnattendFile -destination "$OSDrive`:\Windows\System32\Sysprep"
Send-BootCode -BootDrive $BootDrive -OSDrive $OSDrive
Expand Down
33 changes: 18 additions & 15 deletions DeployNanoServerPhysicalMedia.ps1
Expand Up @@ -6,18 +6,21 @@ $DriverPath='C:\Drivers'
$NanoMedia='C:\'
$WinPeDrive='C'

$Wimfile=New-WindowsPEWim
$CustomNano=New-NanoServerWIM -Mediapath C:\ -Destination C:\NanoTemp -Compute
#$Wimfile=New-WindowsPEWim
$WimFile='C:\PeWim\Custom.wim'

#$CustomNano=New-NanoServerWIM -Mediapath C:\ -Destination C:\NanoTemp -Compute
$CustomNano='C:\NanoTemp\NanoCustom.wim'

$Disk=Get-AttachedDisk -USB -GUI
$Env:WinPERoot="$($WinPEDrive)`:\Program Files$(Get-ArchitectureString)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment"
$WinADK="$($Env:WinPERoot)\amd64"

Remove-item -Path $WinPETemp -Recurse -Force
New-Item -ItemType Directory -Path $WinPETemp -Force
Copy-Item -Path "$WinAdk\Media" -Destination $WinPETemp -Recurse -Force
New-Item -ItemType Directory -Path "$WinPETemp\Media\Sources" -Force
Copy-Item -path "$WinAdk\en-us\winpe.wim" -Destination "$WinPETemp\Media\Sources\boot.wim"
$Result=Remove-item -Path $WinPETemp -Recurse -Force -ErrorAction SilentlyContinue
$Result=New-Item -ItemType Directory -Path $WinPETemp -Force
$Result=Copy-Item -Path "$WinAdk\Media" -Destination $WinPETemp -Recurse -Force
$Result=New-Item -ItemType Directory -Path "$WinPETemp\Media\Sources" -Force
$Result=Copy-Item -path "$WinAdk\en-us\winpe.wim" -Destination "$WinPETemp\Media\Sources\boot.wim"

if ($Wimfile -ne $NULL)
{
Expand All @@ -27,23 +30,23 @@ Copy-Item -Path $Wimfile -Destination "$WinPETemp\Media\Sources\boot.wim"
New-PartitionStructure -Disk $disk -OSDrive $OSDrive -USB -MBR
$WinPEKey=$OsDrive+':'

Copy-Item -Path "$WinPETemp\Media\*" -destination "$WinPeKey\" -Recurse
$Result=Copy-Item -Path "$WinPETemp\Media\*" -destination "$WinPeKey\" -Recurse

Send-BootCode -OSDrive $OSDrive -USB

$Modulepath=Split-path ((get-module deployimage).path)

New-Item -Path "$WinPeKey\DeployImage" -ItemType Directory -Force
Copy-Item -Path "$ModulePath\*" -Destination "$WinPEkey\DeployImage" -Recurse
$Result=New-Item -Path "$WinPeKey\DeployImage" -ItemType Directory -Force
$Result=Copy-Item -Path "$ModulePath\*" -Destination "$WinPEkey\DeployImage" -Recurse

If ($DriverPath -ne $NULL -and (Test-Path $DriverPath))
{
New-Item -Path "$WinPEKey\Drivers" -ItemType Directory -Force
Copy-Item -Path "$DriverPath\*" -Destination "$WinPEkey\Drivers" -Recurse
$Result=New-Item -Path "$WinPEKey\Drivers" -ItemType Directory -Force
$Result=Copy-Item -Path "$DriverPath\*" -Destination "$WinPEkey\Drivers" -Recurse
}

New-Item -Path "$WinPeKey\NanoServer" -ItemType Directory -Force
Copy-Item -Path "$($NanoMedia)NanoServer\*" -Destination "$WinPEKey\NanoServer\" -Recurse
Copy-Item -Path $CustomNano -Destination "$WinPeKey\NanoServer"
$Result=New-Item -Path "$WinPeKey\NanoServer" -ItemType Directory -Force
$Result=Copy-Item -Path "$($NanoMedia)NanoServer\*" -Destination "$WinPEKey\NanoServer\" -Recurse
$Result=Copy-Item -Path $CustomNano -Destination "$WinPeKey\NanoServer"

Remove-DriveLetter -DriveLetter $OSdrive
50 changes: 0 additions & 50 deletions DeployNanoServerVHD.ps1

This file was deleted.

0 comments on commit e1f8402

Please sign in to comment.