Microsoft MVP성태의 닷넷 이야기
Windows: 127. Convert-WindowsImage.ps1 사용 방법 정리 [링크 복사], [링크+제목 복사],
조회: 14419
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

Convert-WindowsImage.ps1 사용 방법 정리

WIM 이미지를 vhd 설치 파일로 변환해주는 PowerShell 스크립트가 있습니다.

Convert-WindowsImage.ps1 - WIM2VHD for Windows 10 (also Windows 8 and 8.1)
; https://gallery.technet.microsoft.com/scriptcenter/Convert-WindowsImageps1-0fe23a8f
; https://www.powershellgallery.com/packages/Convert-WindowsImage/10.0

이 스크립트를 다음과 같은 식으로 그냥 사용하시면 아무 동작도 안 합니다.

PS C:\temp> .\Convert-WindowsImage.ps1 -WIM 'c:\temp\nanoserver\NanoServer.wim' -VHD 'c:\temp\vhd\nanoserver.vhd' -DiskType Fixed -VHDFormat VHD -SizeBytes 10GB -Edition 1

PS C:\temp> 

왜냐하면 Convert-WindowsImage.ps1은 내부에서 Convert-WindowsImage 메서드를 정의만 해두기 때문입니다. 따라서, 다음과 같이 ImportModule을 한 후에 Convert-WindowsImage 메서드를 호출하는 식으로 사용해야 합니다.

Import-Module .\Convert-WindowsImage.ps1

Convert-WindowsImage -WIM 'c:\temp\nanoserver\NanoServer.wim' -VHD 'c:\temp\vhd\nanoserver.vhd' -DiskType Fixed -VHDFormat VHD -SizeBytes 10GB -Edition 1




그런데 다음과 같이 명령을 내려 보면, 웬일인지 예외가 발생합니다.

PS C:\temp> Convert-WindowsImage -WIM 'c:\temp\nanoserver\NanoServer.wim' -VHD 'c:\temp\vhd\nanoserver.vhd' -DiskType Fixed -VHDFormat VHD -SizeBytes 10GB -Edition 1

Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 10
Copyright (C) Microsoft Corporation.  All rights reserved.
Version 10.0.9000.0.amd64fre.fbl_core1_hyp_dev(mikekol).141224-3000 Beta

ERROR  : Cannot convert the "System.String[]" value of type "System.String[]" to type "System.Int32".
INFO   : Log folder is %USERPROFILE%\AppData\Local\Temp\Convert-WindowsImage\6977f150-4e06-4eff-8123-d35b0e37e8e2

INFO   : Closing Windows image...
INFO   : Done.

예외가 발생하는 위치는 Convert-WindowsImage.ps1의 $Edition을 열거하는 코드인데,

$Edition | ForEach-Object -Process {

    $Edition = $PSItem
    
    if ([Int32]::TryParse($Edition, [ref]$null)) {
        $openImage = $openWim[[Int32]$Edition]  // 예외 발생
    } else {
        $openImage = $openWim[$Edition]
    }    

    if ($null -eq $openImage) {
        Write-W2VError "The specified edition does not appear to exist in the specified WIM."
        Write-W2VError "Valid edition names are:"
        $openWim.Images | %{ Write-W2VError "  $($_.ImageFlags)" }
        throw
    }

    ...[생략]...
}

"$Edition = $PSItem" 설정하면서 열거형 변수가 $PSItem으로 겹쳐써져 오류가 발생하는 듯합니다. 그래서 다음과 같이 바꿔주면 정상적으로 동작합니다.

$Edition | ForEach-Object -Process {

    $nEdition = $PSItem
    
    if ([Int32]::TryParse($Edition, [ref]$null)) {
        $openImage = $openWim[[Int32]$nEdition]
    } else {
        $openImage = $openWim[$Edition]
    }    

    if ($null -eq $openImage) {
        Write-W2VError "The specified edition does not appear to exist in the specified WIM."
        Write-W2VError "Valid edition names are:"
        $openWim.Images | %{ Write-W2VError "  $($_.ImageFlags)" }
        throw
    }

    ...[생략]...
}




그 외에, Edition 인자로 숫자(인덱스) 말고 이름을 주는 방법이 있습니다. 이를 위해 WIM 파일에 포함된 Edition 이름을 알아야 하는데, 이는 imagex.exe를 이용해 나열할 수 있습니다.

C:\Program Files (x86)\Windows Kits\10\Tools\bin\i386>imagex /info e:\temp\NanoServer\NanoServer.wim

ImageX Tool for Windows
Copyright (C) Microsoft Corp. All rights reserved.
Version: 6.1.7600.16385

WIM Information:
----------------
Path:        e:\temp\NanoServer\NanoServer.wim
GUID:        {371880ba-0afa-4c84-a233-f1ba2d142e09}
Image Count: 2
Compression: LZX
Part Number: 1/1
Attributes:  0x8
             Relative path junction


Available Image Choices:
------------------------
<WIM>
  <TOTALBYTES>172753493</TOTALBYTES>
  <IMAGE INDEX="1">
    ...[생략]...
    <WINDOWS>
      <ARCH>9</ARCH>
      <PRODUCTNAME>Microsoft® Windows® Operating System</PRODUCTNAME>
      <EDITIONID>ServerStandardNano</EDITIONID>
      ...[생략]...
    </WINDOWS>
    <NAME>Windows Server 2016 SERVERSTANDARDNANO</NAME>
  </IMAGE>
  <IMAGE INDEX="2">
    ...[생략]...
    <WINDOWS>
      <ARCH>9</ARCH>
      <PRODUCTNAME>Microsoft® Windows® Operating System</PRODUCTNAME>
      <EDITIONID>ServerDatacenterNano</EDITIONID>
      ...[생략]...
    </WINDOWS>
    <NAME>Windows Server 2016 SERVERDATACENTERNANO</NAME>
  </IMAGE>
</WIM>

따라서 실행은 이렇게 하시면 됩니다.

Convert-WindowsImage -WIM 'e:\temp\nanoserver\NanoServer.wim' -VHD 'e:\temp\vhd\nanoserver.vhd' -DiskType Fixed -VHDFormat VHD -SizeBytes 10GB -Edition "Windows Server 2016 SERVERSTANDARDNANO"




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/17/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  84  85  86  87  [88]  89  90  ...
NoWriterDateCnt.TitleFile(s)
11438정성태1/17/201812749오류 유형: 446. Error CS0234 The type or namespace name 'ITuple' does not exist in the namespace
11437정성태1/17/201811967VS.NET IDE: 124. Platform Toolset 설정에 따른 Visual C++의 헤더 파일 기본 디렉터리
11436정성태1/16/201813652개발 환경 구성: 352. ASP.NET Core (EXE) 프로세스가 IIS에서 호스팅되는 방법 - ASP.NET Core Module(AspNetCoreModule) [4]
11435정성태1/16/201814494개발 환경 구성: 351. OWIN 웹 서버(EXE)를 IIS에서 호스팅하는 방법 - HttpPlatformHandler (Reverse Proxy)파일 다운로드2
11434정성태1/15/201814783개발 환경 구성: 350. 사용자 정의 웹 서버(EXE)를 IIS에서 호스팅하는 방법 - HttpPlatformHandler (Reverse Proxy)파일 다운로드2
11433정성태1/15/201813125개발 환경 구성: 349. dotnet ef 명령어 사용을 위한 준비
11432정성태1/11/201817079.NET Framework: 726. WPF + Direct2D + SharpDX 출력 C# 예제파일 다운로드2
11431정성태1/11/201816634.NET Framework: 725. C# - 동기 방식이면서 비동기 메서드(awaitable)처럼 구현한 사례 [9]
11430정성태1/10/201819924.NET Framework: 724. WPF + Direct2D 출력 C# 예제 [2]파일 다운로드1
11429정성태1/9/201811550개발 환경 구성: 348. ASP.NET Core 2.1 Preview 버전 적용 방법
11428정성태1/6/201813765개발 환경 구성: 347. WinForm 프로젝트를 WPF 프로젝트 유형으로 변경하는 방법파일 다운로드1
11427정성태1/5/201812245오류 유형: 445. vcpkg 빌드 오류 - Starting the CLR failed with HRESULT 80040153
11426정성태1/5/201821138오류 유형: 444. curl로 호출할 때 발생하는 오류 정리
11425정성태1/4/201811904개발 환경 구성: 346. ASP.NET Core Web Application을 IIS에서 호스팅하는 방법 (2)
11424정성태1/4/201812117개발 환경 구성: 345. ASP.NET Core 프로젝트를 명령행에서 빌드하는 방법
11423정성태1/3/201829097VC++: 123. 내가 만든 코드보다 OpenCV의 속도가 월등히 빠른 이유 [8]파일 다운로드2
11422정성태1/2/201820305.NET Framework: 723. C# - OpenCvSharp 사용 시 C/C++을 이용한 속도 향상 (for 루프 연산) [4]파일 다운로드1
11421정성태1/2/201812526오류 유형: 443. Visual Studio - nuget configuration is invalid
11420정성태12/30/201716110.NET Framework: 722. C# - Windows 10 운영체제의 데스크톱 앱에서 음성인식(SpeechRecognizer) 사용하는 방법 [3]파일 다운로드1
11419정성태12/23/201717941.NET Framework: 721. WebClient 타입의 ...Async 메서드 호출은 왜 await + 동기 호출 시 hang 현상이 발생할까요? [2]파일 다운로드1
11418정성태12/23/201726606.NET Framework: 720. 비동기 메서드 내에서 await 시 ConfigureAwait 호출 의미 [2]파일 다운로드1
11417정성태12/22/201713749.NET Framework: 719. Task를 포함하는 async 메서드의 동작 방식 [2]
11416정성태12/21/201712614.NET Framework: 718. AsyncTaskMethodBuilder.Create() 메서드 동작 방식 [2]
11415정성태12/21/201714129.NET Framework: 717. Task를 포함하지 않는 async 메서드의 동작 방식 [6]
11414정성태12/21/201719626.NET Framework: 716. async 메서드의 void 반환 타입 사용에 대하여파일 다운로드2
11413정성태12/20/201714883개발 환경 구성: 344. 윈도우 10 - TTS 및 음성 인식을 위한 환경 설정
... 76  77  78  79  80  81  82  83  84  85  86  87  [88]  89  90  ...