DaRT) 10 (Microsoft 診斷和修復工具組可讓您使用 PowerShell 命令來完成各種 DaRT 10 系統管理工作或建立 DaRT 復原映像。
使用 PowerShell 執行 DaRT 工作
Microsoft 診斷和修復工具組 (DaRT) 10 提供下列列出的一組Windows PowerShell Cmdlet。 系統管理員可以使用這些 PowerShell Cmdlet,從命令提示字元執行各種 DaRT 10 伺服器工作,而不是從 DaRT 復原映像精靈。
| 名稱 | 描述 |
|---|---|
| Copy-DartImage | 將 ISO 燒錄到 CD、DVD 或 USB 磁碟機。 |
| Export-DartImage | 允許將包含 DaRT 影像的來源 WIM 檔案轉換成 ISO 檔案。 |
| New-DartConfiguration | 建立將 DaRT 工具集套用至 Windows 映像所需的 DaRT 設定物件。 |
| Set-DartImage | 將 DartConfiguration 物件套用至掛接的 Windows 映像。 |
使用 PowerShell 指令碼建立復原映像
您可以使用 PowerShell 指令碼來建立 DaRT 10 復原映像,而不是使用 DaRT 10 復原映像精靈。 此外,DaRT 10 復原映像精靈可以根據您指定的設定,為您執行 PowerShell 指令碼。
以下是 DaRT 10 復原映像精靈所建立的 PowerShell 指令碼範例。
###
### DaRT Image Creation Script
###
### This script was auto generated by the Microsoft DaRT Recovery Image Wizard.
###
### This script uses the DISM and DaRT PowerShell commands to create a bootable DaRT image.
### Both a WIM and ISO file are produced.
###
### Examples of how to burn/copy the DaRT ISO to DVD/USB are available at the end of this script.
###
### This variable tells PowerShell to stop if an error occurs.
$ErrorActionPreference = "Stop";
###
### Import the modules necessary for DaRT Image creation.
###
Import-Module "Dism"
Import-Module "Microsoft.Dart"
###
### Specifies where the Windows media is located and where the ISO and WIM files will be saved.
### These can be changed as necessary.
###
$WinMediaPath = "D:\"; ### This is the path of the Windows media.
$DestinationWimPath = "C:\Users\Administrator\Desktop\DaRT10\x64\boot.wim"; ### Specify where the WIM file will be saved.
$DestinationIsoPath = "C:\Users\Administrator\Desktop\DaRT10\x64\DaRT10.iso"; ### Specify where the ISO will be saved.
###
### These variables are used to specify temporary and output directories based on the paths above.
###
$WimParentPath = (Split-Path -Path "$destinationWimPath" -Parent); ### Specify the directory where the DaRT WIM file will be saved.
$IsoParentPath = (Split-Path -Path "$destinationIsoPath" -Parent); ### This is the directory where the DaRT ISO file will be saved.
$TempMountPath = "$([System.IO.Path]::GetTempPath())\DaRT8Mount_$(Get-Random)"; ### Specify the temporary directory used to mount the Windows image.
###
### Prepare the Windows image.
###
### Verify that the output directories exist.
New-Item -Path $WimParentPath -Type Directory -Force
New-Item -Path $IsoParentPath -Type Directory -Force
New-Item -Path $TempMountPath -Type Directory -Force
### Create a copy of the WIM and remove the read-only attribute.
### The WIM file will be the resulting DaRT image.
Copy-Item "$WinMediaPath\sources\boot.wim" $DestinationWimPath -Force
Set-ItemProperty $DestinationWimPath -Name IsReadOnly -Value $false
### Mount the bootable image within the WIM file (normally index 2).
Mount-WindowsImage -ImagePath $DestinationWimPath -Path $TempMountPath -Index 2
###
### Add additional drivers to the image.
###
### The following is an example of how to add additional drivers to the image.
### Specify the actual path to a driver's INF file and uncomment the following statement.
# Add-WindowsDriver -Path $TempMountPath -Driver "c:\example\path\to\drivers.inf" -ForceUnsigned
###
### Installs the specified WinPE package(s) into the image.
###
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-EnhancedStorage.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WinReCfg.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-FMAPI.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-FontSupport-WinRE.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-EnhancedStorage_en-us.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Scripting_en-us.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WinReCfg_en-us.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFx.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFx_en-us.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-PowerShell_en-us.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-DismCmdlets.cab"
Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-DismCmdlets_en-us.cab"
###
### Add the DaRT tools to the image.
### The New-DartConfiguration cmdlet is used to specify how the DaRT image is configured.
### Modify this statement to configure how the DaRT tools will be applied to the image.
###
$config = New-DartConfiguration -AddComputerManagement -AddCrashAnalyzer -AddDiskCommander -AddDiskWipe -AddExplorer -AddFileRestore -AddFileSearch -AddHotfixUninstall -AddLocksmith -AddRegistryEditor -AddSfcScan -AddSolutionWizard -AddTcpConfig
$config | Set-DartImage -Path $TempMountPath
###
### Perform any manual user-specific customizations here.
###
# Read-Host -Prompt "Script is paused for any manual customization. Press ENTER to continue"
### Save the changes to the WIM file by dismounting the image.
Dismount-WindowsImage -Path $TempMountPath -Save
### Create a bootable DaRT ISO.
Export-DartImage -IsoPath $DestinationIsoPath -WimPath $DestinationWimPath
### The following is an example of how to burn the ISO to a writeable CD/DVD.
### Specify the correct drive letter and uncomment the statement to burn an ISO.
# Copy-DartImage -IsoPath $DestinationIsoPath -Drive "G:" -Type DVD
### The following is an example of how to format and copy the ISO to a USB drive.
### Specify the correct drive letter and uncomment the statement to create a bootable USB.
# Copy-DartImage -IsoPath $DestinationIsoPath -Drive "G:" -Type USB
### Removes all temporary files.
Remove-Item $TempMountPath -Force -Recurse