PowerShell 中使用相关命令管理 FFU(Full Flash Update)映像

PowerShell 中使用相关命令管理 FFU(Full Flash Update)映像的示例:

  1. 获取系统中的 Windows 映像信息:

    powershellCopy Code
    Get-WindowsImage
  2. 挂载指定的 Windows 映像:

    powershellCopy Code
    Mount-WindowsImage -ImagePath "C:\path\to\image.ffu" -Index 1 -Path "C:\mount"
  3. 卸载已挂载的 Windows 映像:

    powershellCopy Code
    Dismount-WindowsImage -Path "C:\mount" -Discard
  4. 导出指定的 Windows 映像到其他位置:

    powershellCopy Code
    Export-WindowsImage -SourcePath "C:\path\to\image.ffu" -DestinationPath "D:\exported_image.ffu" -CompressionType None
  5. 删除指定的 Windows 映像:

    powershellCopy Code
    Remove-WindowsImage -ImagePath "C:\path\to\image.ffu"

以上示例中,C:\path\to\image.ffu 是 FFU 映像文件的路径,-Index 参数用于指定映像的索引(如果有多个映像),C:\mount 是用于挂载映像的目标路径,D:\exported_image.ffu 是导出映像的目标路径。


  1. 获取系统中已安装的 Windows 映像:

    powershellCopy Code
    Get-WindowsImage -Online
  2. 挂载指定路径下的 Windows 映像文件,并指定只读权限:

    powershellCopy Code
    Mount-WindowsImage -ImagePath "C:\path\to\image.ffu" -Index 1 -Path "C:\mount" -ReadOnly
  3. 导出指定 Windows 映像文件中的指定映像到其他位置,并使用最快的压缩算法:

    powershellCopy Code
    Export-WindowsImage -SourcePath "C:\path\to\image.ffu" -Index 2 -DestinationPath "D:\exported_image.wim" -CompressionType Max
  4. 删除指定路径下的 Windows 映像文件:

    powershellCopy Code
    Remove-Item "C:\path\to\image.ffu"

处理 FFU 文件需要使用特定的工具和库。Microsoft 提供了 Windows Imaging and Configuration Designer (ICD) 工具,可以用于创建和操作 FFU 映像。您可以使用 ICD 工具的命令行界面(ICD.exe)来执行这些操作。

以下是一些示例用法:

  1. 捕获物理磁盘映像到新的 FFU 文件:

    powershellCopy Code
    ICD.exe /Capture-Ffu /Image "C:\path\to\captured.ffu"
  2. 应用 FFU 映像:

    powershellCopy Code
    ICD.exe /Apply-Ffu /Image "C:\path\to\image.ffu"
  3. 拆分现有的 FFU 文件为多个只读已拆分 FFU 文件:

    powershellCopy Code
    ICD.exe /Split-Ffu /Image "C:\path\to\image.ffu"
  4. 优化 FFU 文件以适应不同大小的存储:

    powershellCopy Code
    ICD.exe /Optimize-Ffu /Image "C:\path\to\image.ffu"

请确保在运行这些命令之前安装和配置了 Windows Imaging and Configuration Designer (ICD) 工具,并将 ICD.exe 添加到系统的 PATH 环境变量中。


PowerShell 命令实现:

  1. 捕获物理磁盘映像到新的 FFU 文件:

    powershellCopy Code
    New-Item -ItemType File "C:\path\to\captured.ffu"
    cmd /c "dism /Capture-Image /ImageFile:""C:\path\to\captured.wim"" /CaptureDrive:""\\"" /Name:""Captured Image"""
    cmd /c "dism /Export-Image /SourceImageFile:""C:\path\to\captured.wim"" /SourceIndex:1 /DestinationImageFile:""C:\path\to\captured.ffu"" /Compress:fast"
    Remove-Item "C:\path\to\captured.wim"
  2. 应用 FFU 映像:

    powershellCopy Code
    cmd /c "dism /Apply-Image /ImageFile:""C:\path\to\image.ffu"" /ApplyDrive:""\\"" /Index:1"
  3. 拆分现有的 FFU 文件为多个只读已拆分 FFU 文件:

    powershellCopy Code
    $chunkSize = 1024*1024*500 # 每个块的大小,以字节为单位(此处设置为500MB)
    $sourceFile = "C:\path\to\image.ffu" # 要拆分的源文件
    $destinationFolder = "C:\path\to\splitted_ffu" # 拆分后的文件存放目录
    $buffer = New-Object byte[] $chunkSize
    $fileStream = New-Object System.IO.FileStream($sourceFile, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
    $counter = 0
    while (($readBytes = $fileStream.Read($buffer, 0, $chunkSize)) -gt 0) {
        $counter++
        $destinationFile = Join-Path $destinationFolder ("part" + "{0:d3}" -f $counter + ".ffu")
        $fs = New-Object System.IO.FileStream($destinationFile, [System.IO.FileMode]::CreateNew, [System.IO.FileAccess]::Write)
        $fs.Write($buffer, 0, $readBytes)
        $fs.Close()
    }
    $fileStream.Close()
  4. 优化 FFU 文件以适应不同大小的存储:

    powershellCopy Code
    cmd /c "dism /Optimize-Image /ImageFile:""C:\path\to\image.ffu"""

在 PowerShell 中,与 FFU 映像相关的命令是使用 Windows 系统映像管理器(DISM)工具来执行的。下面是一些常见的与 FFU 映像相关的 PowerShell 命令:

  1. 捕获物理磁盘映像到新的 FFU 文件:

    powershellCopy Code
    $capturedFile = "C:\path\to\captured.ffu"
    $captureWimFile = "C:\path\to\captured.wim"
    $captureDrive = "C:"
    
    # 使用 DISM 工具捕获物理磁盘映像为 WIM 文件
    dism /Capture-Image /ImageFile:$captureWimFile /CaptureDrive:$captureDrive /Name:"Captured Image"
    
    # 使用 DISM 工具将 WIM 文件导出为 FFU 文件
    dism /Export-Image /SourceImageFile:$captureWimFile /SourceIndex:1 /DestinationImageFile:$capturedFile /Compress:fast
    
    # 删除临时的 WIM 文件
    Remove-Item -Path $captureWimFile
  2. 应用 FFU 映像:

    powershellCopy Code
    $imageFile = "C:\path\to\image.ffu"
    $applyDrive = "C:"
    
    # 使用 DISM 工具将 FFU 映像应用到指定磁盘
    dism /Apply-Image /ImageFile:$imageFile /ApplyDrive:$applyDrive /Index:1
  3. 拆分现有的 FFU 文件为多个只读已拆分 FFU 文件:

    powershellCopy Code
    $sourceFile = "C:\path\to\image.ffu"
    $destinationFolder = "C:\path\to\splitted_ffu"
    $chunkSize = 500MB  # 拆分大小(此处设置为500MB)
    
    # 使用二进制流读取源文件并拆分为多个文件
    $sourceFileStream = [System.IO.File]::OpenRead($sourceFile)
    $buffer = New-Object byte[] $chunkSize
    $counter = 0
    
    while ($sourceFileStream.Position -lt $sourceFileStream.Length) {
        $counter++
        $destinationFile = Join-Path -Path $destinationFolder -ChildPath ("part{0:d3}.ffu" -f $counter)
        $destinationFileStream = [System.IO.File]::Create($destinationFile)
        
        $bytesRead = $sourceFileStream.Read($buffer, 0, $chunkSize)
        $destinationFileStream.Write($buffer, 0, $bytesRead)
        
        $destinationFileStream.Close()
    }
    
    $sourceFileStream.Close()
  4. 优化 FFU 文件以适应不同大小的存储:

    powershellCopy Code
    $imageFile = "C:\path\to\image.ffu"
    
    # 使用 DISM 工具优化 FFU 映像
    dism /Optimize-Image /ImageFile:$imageFile

  1. 检查 FFU 映像的详细信息:

    powershellCopy Code
    $imageFile = "C:\path\to\image.ffu"
    
    # 使用 DISM 工具获取 FFU 映像的详细信息
    dism /Get-ImageInfo /ImageFile:$imageFile
  2. 挂载 FFU 映像为虚拟磁盘:

    powershellCopy Code
    $imageFile = "C:\path\to\image.ffu"
    $mountPath = "D:\mount"
    
    # 使用 DISM 工具将 FFU 映像挂载为虚拟磁盘
    dism /Mount-Image /ImageFile:$imageFile /MountDir:$mountPath
  3. 卸载虚拟磁盘:

    powershellCopy Code
    $mountPath = "D:\mount"
    
    # 使用 DISM 工具卸载指定的虚拟磁盘
    dism /Unmount-Image /MountDir:$mountPath /Discard
  4. 获取已安装映像的列表:

    powershellCopy Code
    # 使用 DISM 工具获取已安装映像的列表
    dism /Get-WimInfo /WimFile:"C:\Windows\system32\Recovery\WindowsRE\Winre.wim"

 

posted @ 2024-02-04 21:48  suv789  阅读(38)  评论(0编辑  收藏  举报