Tìm kiếm ↓↓↓

Quy trình build bộ cài Windows 10 version 1607 sử dụng Windows Powershell

Chủ đề này trình bày các phương pháp mà  kỹ thuật viên hay người dùng có thể sử dụng Cmdlets trong Windows Powershell thay thế Deployment Imaging Servicing Management (DISM) để build Windows 10 trước khi triển khai trên máy tính. Hiểu theo cách đơn giản thay vì sử dụng các dòng lệnh Dism kèm theo các tùy chọn trong Command Prompt (Cmd) thì chúng ta sẽ sử dụng Cmdlets trong Windows Powershell vì các lập trình viên Microsoft họ đã lập trình sẵn dòng lệnh và chúng ta chỉ triển khai đúng dòng lệnh thôi nghĩa là đúng lệnh thì nó chạy còn sai thì nó báo lỗi không có trong thư viện.


Để các bạn hiểu rõ hơn về sử dụng Cmdlets trong Windows Powershell thay thế cho Dism trong Command Prompt tôi sẽ viết song song cả 2 dòng lệnh tương ứng và bạn có thể sử dụng như nhau rất thuật tiện. Lưu ý phương pháp này phải sử dụng trên máy tính đang cài sẵn Windows 10 và đương nhiên Dism bạn sử dụng trên cmd bạn cũng có thể sử dụng nó trên powershell như ví dụ dòng lệnh Dism /Get-ImageInfo /ImageFile:C:\images\install.wim thay vì bạn gõ trên cmd bạn cũng có thể gõ trên powershell. Một lưu ý quan trọng không kém khi bạn chạy cmd hay powershell phải chạy bằng quyền Administrator mới triển khai dòng lệnh được.

Trước tiên trên phân vùng nào còn trống ví dụ như ổ (C:) bạn tạo mới lần lượt những thư mục sau: setup ( lưu bộ cài win 10), images ( lưu tập tin gắn kết hình ảnh install.wim) , packages ( lưu các bản cập nhật kb msu, cab ), offline ( mount install.wim ), drivers ( lưu driver) và iso ( lưu iso mới ).

Tìm đến iso win 10 mount nó ra ổ ảo ( chuột phải iso chọn Mount ), truy cập ổ ảo copy tất cả vào thư mục setup.


Khi copy xong bạn lại truy cập thư mục sources của thư mục setup di chuyển tập tin install.wim vào thư mục images


Truy cập địa chỉ sau trên trình duyệt: http://www.catalog.update.microsoft.com/Home.aspx để tải các gói cập nhật kb msu hoặc cab về máy và lưu trong thư mục packages. Gõ tên gói kb vào khung tìm kiếm và tải về máy chẳng hạn như kb3216755, lưu ý nền tảng của bộ cài 32 hay 64 bit mà tải về gói tương ứng.


1. Xem tên phiên bản windows trong tập tin gắn kết install.wim lưu trong thư mục images:

- windows powershell:
Get-WindowsImage –ImagePath C:\images\install.wim

- cmd:
Dism /Get-ImageInfo /ImageFile:C:\images\install.wim

2. Mount tập tin gắn kết install.wim vào thư mục offline:

- windows powershell:
Mount-WindowsImage –ImagePath C:\images\install.wim –Index 1 –Path C:\offline

- cmd:
Dism /Mount-Image /ImageFile:C:\images\install.wim /Index:1 /MountDir:C:\offline

3. Xem thông tin Edition trong thư mục đã mount install.wim có thể nâng cấp lên phiên bản nào:

- windows powershell:
Get-WindowsEdition –Path C:\offline -Target

- cmd:
Dism /Image:C:\offline /Get-TargetEditions

4. Giả sử bạn muốn chuyển phiên bản Enterprise sang Education:

- windows powershell:
Set-WindowsEdition –Path C:\offline –Edition Education

- cmd:
Dism /Image:C:\offline /Set-Edition:Education

5. Chèn key kích hoạt cho phiên bản Education sau khi chuyển:

- windows powershell:
Set-WindowsProductKey –Path C:\offline –ProductKey YNMGQ-8RYV3-4PGQ3-C8XTP-7CFBY

- cmd:
Dism /Image:C:\offline /Set-ProductKey:YNMGQ-8RYV3-4PGQ3-C8XTP-7CFBY

6. Tích hợp các gói packages kb trong thư mục packages:

- windows powershell:
Add-WindowsPackage –Path C:\offline –PackagePath C:\packages

- cmd:
Dism /Image:C:\offline /Add-Package /Packagepath:C:\packages

7. Xem thông tin các gói packages đã được tích hợp:

- windows powershell:
Get-WindowsPackage –Path C:\offline

- cmd:
Dism /Image:C:\offline /Get-Packages


8. Gỡ bỏ một gói package đã được tích hợp:

Ví dụ bạn muốn gỡ bỏ gói package mặc định có tên Microsoft-Windows-ContactSupport-Package~31bf3856ad364e35~amd64~~10.0.14393.0

- windows powershell:
Remove-WindowsPackage –Path C:\offline –PackageName  Microsoft-Windows-ContactSupport-Package~31bf3856ad364e35~amd64~~10.0.14393.0

- cmd:
Dism /Image:C:\offline /Remove-Package /PackageName:Microsoft-Windows-ContactSupport-Package~31bf3856ad364e35~amd64~~10.0.14393.0

9. Xem tính năng Features có sẵn và trạng thái của nó:

- windows powershell:
Get-WindowsOptionalFeature –Path C:\offline

- cmd:
Dism /Image:C:\offline /Get-Features


10. Kích hoạt tính năng đang ở trạng thái Disable

Giả sử bạn muốn kích hoạt Net Framework 3.5

- windows powershell:
Enable-WindowsOptionalFeature –Path C:\offline –FeatureName NetFx3 –Source C:\setup\sources\sxs -All -LimitAccess

- cmd:
Dism /Image:C:\offline /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:C:\setup\sources\sxs

11. Tắt tính năng đang ở trạng thái Enable:

Giả sử bạn muốn tắt trình duyệt Internet Explorer 11

- windows powershell:
Disable-WindowsOptionalFeature –Path C:\offline –FeatureName Internet-Explorer-Optional-amd64

- cmd:
Dism /Image:C:\offline /Disable-Feature /FeatureName:Internet-Explorer-Optional-amd64

12. Xem các ứng dụng windowsapps được tích hợp mặc định:

- windows powershell:
Get-AppxProvisionedPackage –Path C:\offline

- cmd:
Dism /Image:C:\offline /Get-ProvisionedAppxPackages


13. Gõ bỏ ứng dụng

Giả sử bạn muốn gỡ bỏ ứng dụng 3DBuilder

- windows powershell:
Remove-AppxProvisionedPackage –Path C:\offline –PackageName Microsoft.3DBuilder_11.0.47.0_neutral_~_8wekyb3d8bbwe

- cmd:
Dism /Image:C:\offline /Remove-ProvisionedAppxPackage /PackageName:Microsoft.3DBuilder_11.0.47.0_neutral_~_8wekyb3d8bbwe

14. Sao lưu driver từ hệ điều hành đang cài trên máy

Giả sử bạn đang build bộ cài để cài lại trên chính máy của mình hay trên máy tính khác cùng cấu hình, bạn có thể sao lưu driver đã được tích hợp sẵn trong Windows 10 đang cài trên máy và sử dụng tích hợp vào bộ cài.

- windows powershell:
Export-WindowsDriver -Online -Destination C:\drivers

- cmd:
Dism /Online /Export-Driver /Destination:C:\drivers

15. Tích hợp driver

- windows powershell:
Add-WindowsDriver –Path C:\offline –Driver C:\drivers –Recurse

- cmd:
Dism /Image:C:\offline /Add-Driver /Driver:C:\drivers /Recurse

16. Xem thông tin driver đã tích hợp:

- windows powershell:
Get-WindowsDriver –Path C:\offline

- cmd:
Dism /Image:C:\offline /Get-Drivers


17. Gỡ bỏ driver đã tích hợp:

- windows powershell:
Remove-WindowsDriver –Path C:\offline –Driver OEM1.inf

- cmd:
Dism /Image:C:\offline /Remove-Drivers /Driver:OEM1.inf

18. Làm sạch hệ thống trước khi Unmount

- windows powershell:
Repair-WindowsImage -Path C:\offline -RestoreHealth

- cmd:
Dism /Image:C:\offline /Cleanup-Image /RestoreHealth

19. Umount thư mục offline về lại tập tin gắn kết install.wim

- windows powershell:
Dismount-WindowsImage –Path C:\offline -Save

- cmd:
Dism /Unmount-Image /MountDir:C:\offline /Commit

20. Export install.wim sang định dạng esd cho độ nén cao hơn

Sau khi tích hợp các gói cập nhật và driver thì tập tin install.wim 64 bit thường có dung lượng lớn hơn 4gb như vậy không thể chép vào usb với định dạng Fat32 được, do vậy bạn cần nén nó lại sang định dạng install.esd

- windows powershell:
Export-WindowsImage -SourceImagePath C:\images\install.wim -SourceIndex 1 -DestinationImagePath C:\setup\sources\install.esd -CompressionType maximum -CheckIntegrity

- cmd:
Dism /Export-Image /SourceImageFile:C:\images\install.wim /SourceIndex:1 /DestinationImageFile:C:\setup\sources\install.esd /Compress:max /CheckIntegrity

21. Chia nhỏ install.wim sang định dạng install.swm, install.swm2, install.swm3...

Nếu bạn không muốn nén sang esd bạn có thể chia nhỏ install.wim sang những định dạng install.swm, install.swm2, install.swm3... cho dung lượng bé hơn 4gb có thể chép vào usb với định dạng Fat32

- windows powershell:
Split-WindowsImage -ImagePath C:\images\install.wim -SplitImagePath C:\setup\sources\install.swm -FileSize 3700 -CheckIntegrity

- cmd:
Dism /Split-Image /ImageFile:C:\images\install.wim /SWMFile:C:\setup\sources\install.swm /FileSize:3700

22. Phần mở rộng:

Phần mở rộng được thực hiện trước phần 19 unmount thư mục offline. Xem bài viết Quy trình build bộ cài Windows 10 rút gọn mà không phải cài đặt trước trên máy ảo để tùy biến, thêm thư mục Panther có lưu file Unattend trả lời cài đặt tự động, Thư mục Scripts có file SetupComplete.cmd...

Phổ biến trong tuần

Tin Tức