PowerShell: Rasmus Linnamäe, WindowsPE skript: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 23: | Line 23: | ||
.LINKS | .LINKS | ||
https://wiki.itcollege.ee/index.php/PowerShell:_Rasmus_Linnamäe,_WindowsPE_skript | https://wiki.itcollege.ee/index.php/PowerShell:_Rasmus_Linnamäe,_WindowsPE_skript | ||
http://technet.microsoft.com/en-us/library/dd799312(WS.10).aspx) | |||
Revision as of 10:38, 27 January 2012
<#
.SYNOPSIS
WindowsPE image faili tegemise skript, toetab ka USB ketast.
.DESCRIPTION
Skript mis teeb WindowsPE-ga image faili, lisades sinna kõik saada olevad lisa pakkid.
USB ketta puhul formaaditakse see ja alles siis paigaldatakse vajalikud failid.
.NOTES
Author Rasmus Linnamäe
Skripti eelduseks on, et on paigaldatud WAIK
Lisada saab ka draiverite kausta, see muutuja ei ole kohustuslik, töötab ka ilma.
Kui ei ole ühendatud ühtegi USB ketast, siis seatakse tema väärtuseks null.
USB ketta puhul loodatkse ajutine kaust C:\Temp\waik, kust hiljem kopeeritakse vajalikud kettale.
WindowsPE lisa pakke mis lisatakse on kokku 10.(http://technet.microsoft.com/en-us/library/dd799312(WS.10).aspx).
Ei lisata WinPE-SRT, kuna see puudub uuemast versioonist.
USB ketas formaaditakse FAT32.
LOodud iso fail on kujul $Name`_$Architecture($Timestamp).iso
.LINKS
https://wiki.itcollege.ee/index.php/PowerShell:_Rasmus_Linnamäe,_WindowsPE_skript
http://technet.microsoft.com/en-us/library/dd799312(WS.10).aspx)
#>
CLS;
# Kontroll, kas WAIK on paigaldatud
IF ((Get-WmiObject Win32_Product | Where-Object {$_.name -eq "Windows Automated Installation Kit"}))
{
Write-Host "WAIK on paigaldatud" -ForegroundColor Yellow}
Else
{
Write-Host "WAIK peab olema paigaldatud, edasiseks skripti tööks. Paigalda WAIK, siis ürita uuesti" -ForegroundColor Red
Break
}
# Küsib kasutajalt vajalikud andmed(muutujad)
$BuildDir = read-host "Sisesta image faili paigaldus asukoht"
$Architecture = read-host "Sisesta arhitektuuri tüüp mida soovid kasutada (x86, amd64, ia64)"
$DriversDir = read-host "Sisesta lisatavate driverite kausta asukoht"
$Name = read-host "Sisesta loodavale image failile nimi"
# Teiste muutujate väärstustamine
$WAIK = "C:\Program Files\Windows AIK\Tools\PETools\$Architecture\WinPE_FPs"
$ImageX = "C:\Program Files\Windows AIK\Tools\$Architecture\imagex.exe"
$Copype = "C:\Program Files\Windows AIK\Tools\PETools\copype.cmd"
$Oscdimg = "C:\Program Files\Windows AIK\Tools\$Architecture\oscdimg.exe"
#USB ketta kontrolli muutuja väärtustamine
$usb = Get-WmiObject -Class Win32_LogicalDisk | Where-Object {$_.DriveType -eq 2}
# USB ketta olemasolu kontroll, kui on olemas ning soovitakse sinna image fail luua, luuakse ajutine kataloog C:\Temp\waik,
#kust hiljem kopeeritake vajalikud failid usb kettale.
$usb | ForEach {
$device = $_.DeviceID }
if (!$device){
$device = "0"
}
if ($device[0] -eq $BuildDir[0] ) {
$BuildDir = "C:\Temp\waik"
}
# Lisa parameetrit väärtustamine
$BootWIM = $BuildDir + "\ISO\sources\boot.wim"
$Mount = $BuildDir + "\mount"
#Dismi pooleli olevate image kustutamine
& "$ImageX" /Cleanup
#Copype käivitamine, et luua WinPE image
& "$Copype" $Architecture $BuildDir
#WIM image liigutamine
Move-Item "$BuildDir\winpe.wim" "$BootWIM"
#Wim faili mountimine
& "$ImageX" /MOUNTRW "$BootWIM" 1 "$Mount"
# Kõikde pakkide lisamine image faili
Dism /Image:$Mount /Add-Package /PackagePath:"$WAIK\winpe-hta.cab" /PackagePath:"$WAIK\winpe-legacysetup.cab",
/PackagePath:"$WAIK\winpe-mdac.cab" /PackagePath:"$WAIK\winpe-pppoe.cab" /PackagePath:"$WAIK\winpe-scripting.cab",
/PackagePath:"$WAIK\winpe-setup.cab" /PackagePath:"$WAIK\winpe-setup-client.cab" /PackagePath:"$WAIK\winpe-setup-server.cab",
/PackagePath:"$WAIK\winpe-wds-tools.cab" /PackagePath:"$WAIK\winpe-wmi.cab"
#Driverite lisamine image faili
Dism /Image:$Mount /Add-Driver /Driver:$DriversDir /Recurse
#Image fail unmountitakse
& "$ImageX" /Unmount "$Mount" /Commit
#Ajaformaat image faili nimele
$TimeStamp = Get-Date -Format dd-MM-yyy
#USB ketta puhul formaatidatakse see ja kopeeritake sinna vajalikud failid
$usb | ForEach {
$device = $_.DeviceID }
if ($BuildDir -eq "C:\Temp\waik" ) {
$command= @"
list volume
select volume="$device"
clean
create partition primary
select partition 1
active
format fs=fat32 quick
assigne letter="$device"
exit
"@
$command|
DiskPart
xcopy $BuildDir\ISO\*.* $device\ /s/e/f
Write-Host "Skript on lõpetanud töö, fail asub $device kettal" -ForegroundColor Yellow
}
#Image faili loomine
else {& "$Oscdimg" -n "-b$BuildDir\etfsboot.com" "$BuildDir\ISO" "$BuildDir\$Name`_$Architecture($Timestamp).iso"
Write-Host "Skript on lõpetanud töö, fail asub $BuildDir\$Name`_$Architecture($Timestamp).iso" -ForegroundColor Yellow}