ChatGPT. Form 을

이전 게시물

2023년 2월 25일 – (ChatGPT) – ChatGPT. VHDX 복사, 새 VM 스크립트 병합

2023년 3월 1일 – (ChatGPT) – ChatGPT. Powershell 관리자 권한으로 실행되는 스크립트 생성

전에 서면으로 완벽한 스크립트는 더 나아가 똑같은 것.

# Check if script is running as Administrator
if (-not ((Security.Principal.WindowsPrincipal)(Security.Principal.WindowsIdentity)::GetCurrent()).IsInRole((Security.Principal.WindowsBuiltInRole)::Administrator)) {
    # Restart script as Administrator
    Start-Process powershell.exe "-File `"$PSCommandPath`"" -Verb RunAs
    exit
}


#Part 1: 정보 입력
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing


$VMName = Read-Host "Enter the name of the virtual machine"
$VMProcessorCount = Read-Host "Enter the number of processors"

$VHDXFolders = Get-ChildItem -Path "F:\sysprepVHD" -Directory
$VHDXFiles = @()


$MemoryOptions = @{
    "2 GB" = 2GB
    "4 GB" = 4GB
    "8 GB" = 8GB
    "10 GB" = 10GB
    "16 GB" = 16GB
    "32 GB" = 32GB
}

$form = New-Object System.Windows.Forms.Form
$form.Text="Select the amount of memory"
$form.Size = New-Object System.Drawing.Size(300, 200)
$form.StartPosition = 'CenterScreen'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75, 120)
$okButton.Size = New-Object System.Drawing.Size(75, 23)
$okButton.Text="OK"
$okButton.DialogResult = (System.Windows.Forms.DialogResult)::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150, 120)
$cancelButton.Size = New-Object System.Drawing.Size(75, 23)
$cancelButton.Text="Cancel"
$cancelButton.DialogResult = (System.Windows.Forms.DialogResult)::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 20)
$label.Size = New-Object System.Drawing.Size(280, 20)
$label.Text="Please select the amount of memory:"
$form.Controls.Add($label)

$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10, 40)
$listBox.Size = New-Object System.Drawing.Size(260, 20)
$listBox.Height = 80

(void) $listBox.Items.AddRange($MemoryOptions.Keys)

$form.Controls.Add($listBox)

$form.Topmost = $true

$result = $form.ShowDialog()

if ($result -eq (System.Windows.Forms.DialogResult)::OK) {
    $SelectedMemory = $listBox.SelectedItem
    $VMMemoryStartupBytes = $MemoryOptions($SelectedMemory)

    $Switches = Get-VMSwitch | Select-Object -Property Name
    $form = New-Object System.Windows.Forms.Form
    $form.Text="Select a virtual switch"
    $form.Size = New-Object System.Drawing.Size(300,200)
    $form.StartPosition = 'CenterScreen'

    $okButton = New-Object System.Windows.Forms.Button
    $okButton.Location = New-Object System.Drawing.Point(75, 120)
    $okButton.Size = New-Object System.Drawing.Size(75, 23)
    $okButton.Text="OK"
    $okButton.DialogResult = (System.Windows.Forms.DialogResult)::OK
    $form.AcceptButton = $okButton
    $form.Controls.Add($okButton)

    $cancelButton = New-Object System.Windows.Forms.Button
    $cancelButton.Location = New-Object System.Drawing.Point(150, 120)
    $cancelButton.Size = New-Object System.Drawing.Size(75, 23)
    $cancelButton.Text="Cancel"
    $cancelButton.DialogResult = (System.Windows.Forms.DialogResult)::Cancel
    $form.CancelButton = $cancelButton
    $form.Controls.Add($cancelButton)

    $label = New-Object System.Windows.Forms.Label
    $label.Location = New-Object System.Drawing.Point(10, 20)
    $label.Size = New-Object System.Drawing.Size(280, 20)
    $label.Text="Please select a virtual switch:"
    $form.Controls.Add($label)

    $listBox1 = New-Object System.Windows.Forms.ListBox
    $listBox1.Location = New-Object System.Drawing.Point(10, 40)
    $listBox1.Size = New-Object System.Drawing.Size(260, 20)
    $listBox1.Height = 80

    (void) $listBox1.Items.AddRange($Switches.Name)

    $form.Controls.Add($listBox1)

    $form.Topmost = $true

    $result = $form.ShowDialog()
    $SelectedSwitch = $listBox1.SelectedItem
}


#Part2 Copy VHDX

foreach ($Folder in $VHDXFolders) {
    $VHDXFiles += Get-ChildItem -Path $Folder.FullName -Filter *.vhdx
}

$VHDXFileNames = @()
foreach ($File in $VHDXFiles) {
    $VHDXFileNames += $File.Name
}

$form = New-Object System.Windows.Forms.Form
$form.Text="Select a VHDX file"
$form.Size = New-Object System.Drawing.Size(300, 200)
$form.StartPosition = 'CenterScreen'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75, 120)
$okButton.Size = New-Object System.Drawing.Size(75, 23)
$okButton.Text="OK"
$okButton.DialogResult = (System.Windows.Forms.DialogResult)::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150, 120)
$cancelButton.Size = New-Object System.Drawing.Size(75, 23)
$cancelButton.Text="Cancel"
$cancelButton.DialogResult = (System.Windows.Forms.DialogResult)::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 20)
$label.Size = New-Object System.Drawing.Size(280, 20)
$label.Text="Please select a VHDX file:"
$form.Controls.Add($label)

$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10, 40)
$listBox.Size = New-Object System.Drawing.Size(260, 20)
$listBox.Height = 80

(void) $listBox.Items.AddRange($VHDXFileNames)

$form.Controls.Add($listBox)

$form.Topmost = $true

$result = $form.ShowDialog()

if ($result -eq (System.Windows.Forms.DialogResult)::OK) {
    $SelectedFile = $listBox.SelectedItem
    $SelectedFilePath = ($VHDXFiles | Where-Object { $_.Name -eq $SelectedFile }).FullName
    
    $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
    $SaveFileDialog.InitialDirectory = (Environment)::GetFolderPath("Desktop")
    $SaveFileDialog.Filter = "VHDX files (*.vhdx)|*.vhdx"
    $SaveFileDialog.FileName = $SelectedFile

    if ($SaveFileDialog.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
        $NewFolderPath = (System.IO.Path)::GetDirectoryName($SaveFileDialog.FileName)
        $NewFileName = (System.IO.Path)::GetFileName($SaveFileDialog.FileName)

        if (!
(Test-Path $NewFolderPath)) { New-Item -ItemType Directory -Path $NewFolderPath } $BufferSize = 1024 * 1024 $Buffer = New-Object byte() $BufferSize $SourceStream = (System.IO.File)::OpenRead($SelectedFilePath) $DestinationStream = (System.IO.File)::Create($NewFolderPath + "\" + $NewFileName) $BytesRead = 0 $TotalBytes = (System.Math)::Min($SourceStream.Length, (System.Int64)::MaxValue) $BytesCopied = 0 while (($BytesRead = $SourceStream.Read($Buffer, 0, $BufferSize)) -gt 0) { $DestinationStream.Write($Buffer, 0, $BytesRead) $BytesCopied += $BytesRead Write-Progress -Activity "Copying $SelectedFile" -PercentComplete ((System.Int32)(100 * $BytesCopied / $TotalBytes)) } $SourceStream.Close() $DestinationStream.Close() } } #Part 3: New-VM $VHDLocation = Split-Path -Path $DestinationStream.Name $VHDs = $DestinationStream.Name if ($result -eq (System.Windows.Forms.DialogResult)::OK) { New-VM -Name $VMName -MemoryStartupBytes $VMMemoryStartupBytes -Generation 2 -Path $VHDLocation -SwitchName $SelectedSwitch -VHDPath $VHDs Set-VM -Name $VMName -ProcessorCount $VMProcessorCount Start-VM -Name $VMName }

하지만 여기 VHDX파일은 에게 최고 스크롤 나갈 때 선택하다 그것은 불편한 답장 메시지 받다.


그만큼 부분 접합재 선택하다 -> 결정적인 VHDX 선택에 의해 변화 노력하겠습니다.

GPT에게 전체 스크립트 분석하다 요청 반품, 더 나아가 함께 물었다.



ChatGPT 답장

스크립트가 F:\sysprep의 폴더만 표시하고 사용자가 사용하려는 VHDX 파일을 탐색할 수 있도록 파트 2를 변경하려면 $VHDXFolders 및 $ VHDXFileNames 배열을 포함하는 코드 블록을 다음으로 바꿉니다.

사용자가 폴더를 선택할 수 있는 폴더 브라우저 대화 상자를 표시한 다음 사용자가 VHDX 파일을 선택할 수 있는 파일 대화 상자를 표시하는 코드입니다.

다음은 파트 2를 변경할 수 있는 방법의 예입니다.

대본 에프:\sysprep사용자가 사용할 VHDX 파일을 찾아볼 수 있도록 $VHDXFolders 및 $VHDXFileNames 배열의 폴더만 표시하도록 파트 2를 변경하려면 폴더 브라우저 대화 상자를 표시한 다음 사용자가 포함을 선택할 수 있는 VHDX 파일을 표시합니다.

대화 상자를 표시하는 코드입니다.

다음은 파트 2를 수정하는 방법의 예입니다.

#Part 2: Copy VHDX

$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$folderBrowser.SelectedPath = "F:\sysprepVHD"
$folderBrowser.Description = "Select the folder containing the VHDX file"

if ($folderBrowser.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
    $VHDXFolder = $folderBrowser.SelectedPath

    $fileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $fileDialog.InitialDirectory = $VHDXFolder
    $fileDialog.Filter = "VHDX files (*.vhdx)|*.vhdx"
    $fileDialog.Title = "Select the VHDX file"
    
    if ($fileDialog.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
        $SelectedFilePath = $fileDialog.FileName
        
        $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
        $SaveFileDialog.InitialDirectory = (Environment)::GetFolderPath("Desktop")
        $SaveFileDialog.Filter = "VHDX files (*.vhdx)|*.vhdx"
        $SaveFileDialog.FileName = (System.IO.Path)::GetFileName($SelectedFilePath)

        if ($SaveFileDialog.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
            $NewFolderPath = (System.IO.Path)::GetDirectoryName($SaveFileDialog.FileName)
            $NewFileName = (System.IO.Path)::GetFileName($SaveFileDialog.FileName)

            if (!
(Test-Path $NewFolderPath)) { New-Item -ItemType Directory -Path $NewFolderPath } $BufferSize = 1024 * 1024 $Buffer = New-Object byte() $BufferSize $SourceStream = (System.IO.File)::OpenRead($SelectedFilePath) $DestinationStream = (System.IO.File)::Create($NewFolderPath + "\" + $NewFileName) $BytesRead = 0 $TotalBytes = (System.Math)::Min($SourceStream.Length, (System.Int64)::MaxValue) $BytesCopied = 0 while (($BytesRead = $SourceStream.Read($Buffer, 0, $BufferSize)) -gt 0) { $DestinationStream. Write($Buffer, 0, $BytesRead) $BytesCopied += $BytesRead Write-Progress -Activity "Copying $SelectedFile" -PercentComplete ((System.Int32)(100 * $BytesCopied / $TotalBytes)) } $SourceStream. Close() $DestinationStream. Close() } } }

이 수정된 코드는 사용자가 F:\sysprep에서 폴더를 선택할 수 있는 폴더 브라우저 대화 상자를 표시합니다.

폴더를 선택하면 파일 대화 상자가 나타나 사용자가 선택한 폴더에서 VHDX 파일을 선택할 수 있습니다.

선택한 VHDX 파일은 원본 스크립트와 마찬가지로 파일 저장 대화 상자를 사용하여 새 위치로 복사됩니다.

이 코드는 사용자가 가상 ​​머신에 사용할 단일 VHDX 파일만 선택한다고 가정합니다.

여러 VHDX 파일 선택을 지원해야 하는 경우 그에 따라 스크립트를 수정해야 합니다.

이 수정된 코드는 사용자가 에프:\sysprep폴더를 선택할 수 있는 폴더 브라우저 대화 상자를 표시합니다.

폴더를 선택하면 사용자가 선택한 폴더에서 VHDX 파일을 선택할 수 있는 파일 대화 상자가 표시됩니다.

선택한 VHDX 파일은 원래 스크립트에서와 같이 파일 저장 대화 상자를 사용하여 새 위치로 복사됩니다.

이 코드를 사용하면 사용자가 단일 VHDX 파일만 선택하여 가상 머신을 만들 수 있습니다.

여러 VHDX 파일 선택을 지원해야 하는 경우 그에 따라 스크립트를 수정해야 합니다.


보정 ~ 후에 스크립트 당신이 걸을 때 더 나아가 함께 나타납니다.

접합재 선택하다 -> 결정적인 길에서 VHDX 파일은 보이는 형식은 아니요.


연구원 창문 열리는 방법 결정을 내리다 만들다 ~이 되다,


기존 유 또한 복사하다 할 것이다 위치 선택하다 것이 가능하다.


복사 완료되면VM그만큼 달릴 것이다.


하지만 무엇 용서. 접합재 확장 중 VHDX 파일 한 번에 당신이 선택하는 경우 착하게 굴 어라 물건 똑같은 것.

아래에 화면에 VHDX붓다 끝까지 선택하다 숫자 ~하도록 하다 변경하거나


아니면 완전히 새로운 아래에 화면 나타나다 결정을 내리다 할 것이다 숫자 있다 구조에 변해야 한다 할 것이다 물건 똑같은 것.


폴더 브라우저 대화상자 ~처럼


OpenFileDialog 모양으로 교환 적합하다 물건 똑같은 것.


그만큼 부분 미러링하다 GPT에게 나는 요청할 것이다.

물어볼게.



ChatGPT 답장

예, 사용자가 VHDX 파일을 직접 선택할 수 있도록 처음부터 OpenFileDialog를 사용하도록 스크립트를 수정할 수 있습니다.

다음은 OpenFileDialog를 사용하도록 파트 2를 변경하는 방법의 예입니다.

예, 사용자가 VHDX 파일을 직접 선택할 수 있도록 처음부터 OpenFileDialog를 사용하도록 스크립트를 수정할 수 있습니다.

다음은 OpenFileDialog를 사용하기 위해 2부를 변경한 예입니다.

#Part 2: Copy VHDX

$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.InitialDirectory = "F:\sysprepVHD"
$openFileDialog.Filter = "VHDX files (*.vhdx)|*.vhdx"
$openFileDialog.Title = "Select the VHDX file"

if ($openFileDialog.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
    $SelectedFilePath = $openFileDialog.FileName
    
    $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
    $SaveFileDialog.InitialDirectory = (Environment)::GetFolderPath("Desktop")
    $SaveFileDialog.Filter = "VHDX files (*.vhdx)|*.vhdx"
    $SaveFileDialog.FileName = (System.IO.Path)::GetFileName($SelectedFilePath)

    if ($SaveFileDialog.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
        $NewFolderPath = (System.IO.Path)::GetDirectoryName($SaveFileDialog.FileName)
        $NewFileName = (System.IO.Path)::GetFileName($SaveFileDialog.FileName)

        if (!
(Test-Path $NewFolderPath)) { New-Item -ItemType Directory -Path $NewFolderPath } $BufferSize = 1024 * 1024 $Buffer = New-Object byte() $BufferSize $SourceStream = (System.IO.File)::OpenRead($SelectedFilePath) $DestinationStream = (System.IO.File)::Create($NewFolderPath + "\" + $NewFileName) $BytesRead = 0 $TotalBytes = (System.Math)::Min($SourceStream.Length, (System.Int64)::MaxValue) $BytesCopied = 0 while (($BytesRead = $SourceStream.Read($Buffer, 0, $BufferSize)) -gt 0) { $DestinationStream. Write($Buffer, 0, $BytesRead) $BytesCopied += $BytesRead Write-Progress -Activity "Copying $SelectedFile" -PercentComplete ((System.Int32)(100 * $BytesCopied / $TotalBytes)) } $SourceStream. Close() $DestinationStream. Close() } }

이 수정된 코드는 OpenFileDialog를 사용하여 사용자가 VHDX 파일을 직접 선택할 수 있도록 합니다.

파일을 선택하면 파일 저장 대화 상자가 나타나 사용자가 원래 스크립트에서와 같이 VHDX 파일의 새 위치와 이름을 선택할 수 있습니다.

이 코드는 사용자가 가상 ​​머신에 사용할 단일 VHDX 파일만 선택한다고 가정합니다.

여러 VHDX 파일 선택을 지원해야 하는 경우 그에 따라 스크립트를 수정해야 합니다.

이 수정된 코드는 OpenFileDialog를 사용하여 사용자가 VHDX 파일을 직접 선택할 수 있도록 합니다.

파일을 선택한 후 파일 저장 대화 상자가 나타나 사용자가 원래 스크립트에서와 같이 VHDX 파일의 새 위치와 이름을 선택할 수 있습니다.

이 코드는 사용자가 가상 ​​머신에 사용할 단일 VHDX 파일을 선택합니다.

여러 VHDX 파일 선택을 지원해야 하는 경우 그에 따라 스크립트를 수정해야 합니다.


OpenFileDialog에게 형질 들어갔다 반품, 직업 구조에 변경되었습니다.


아래에 지역만 지정된 반품, 관련된 지역만 달리다.



$openFileDialog~에 어떻게 기인하다 결정된 만약에 식별하다 숫자 있다.


$openFileDialog.ShowDialog() 붓다 당신이 걸을 때,


의도 한대로 빨리 소환되다 물건 계란 숫자 있다.


그리고 VHDX 파일 컴퓨터에 저장 지도 자주 사용 위치로 바꾸자.

$savefiledialog.InitialDirectory 붓다 디:\~처럼 변경.


똑같은 것 어떤 식으로 구출 물건 계란 숫자 있다. 아래에 재산 가치 보다 열려 있는수업 컴퓨터에 저장~에서 기인하다 차이점 계란 숫자 있다.


최종 버전 더 나아가 똑같은 것.

# Check if script is running as Administrator
if (-not ((Security.Principal.WindowsPrincipal)(Security.Principal.WindowsIdentity)::GetCurrent()).IsInRole((Security.Principal.WindowsBuiltInRole)::Administrator)) {
    # Restart script as Administrator
    Start-Process powershell.exe "-File `"$PSCommandPath`"" -Verb RunAs
    exit
}


#Part 1: 정보 입력
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing


$VMName = Read-Host "Enter the name of the virtual machine"
$VMProcessorCount = Read-Host "Enter the number of processors"


$MemoryOptions = @{
    "2 GB" = 2GB
    "4 GB" = 4GB
    "8 GB" = 8GB
    "10 GB" = 10GB
    "16 GB" = 16GB
    "32 GB" = 32GB
}

$form = New-Object System.Windows.Forms.Form
$form.Text="Select the amount of memory"
$form.Size = New-Object System.Drawing.Size(300, 200)
$form.StartPosition = 'CenterScreen'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75, 120)
$okButton.Size = New-Object System.Drawing.Size(75, 23)
$okButton.Text="OK"
$okButton.DialogResult = (System.Windows.Forms.DialogResult)::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150, 120)
$cancelButton.Size = New-Object System.Drawing.Size(75, 23)
$cancelButton.Text="Cancel"
$cancelButton.DialogResult = (System.Windows.Forms.DialogResult)::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 20)
$label.Size = New-Object System.Drawing.Size(280, 20)
$label.Text="Please select the amount of memory:"
$form.Controls.Add($label)

$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10, 40)
$listBox.Size = New-Object System.Drawing.Size(260, 20)
$listBox.Height = 80

(void) $listBox.Items.AddRange($MemoryOptions.Keys)

$form.Controls.Add($listBox)

$form.Topmost = $true

$result = $form.ShowDialog()

if ($result -eq (System.Windows.Forms.DialogResult)::OK) {
    $SelectedMemory = $listBox.SelectedItem
    $VMMemoryStartupBytes = $MemoryOptions($SelectedMemory)

    $Switches = Get-VMSwitch | Select-Object -Property Name
    $form = New-Object System.Windows.Forms.Form
    $form.Text="Select a virtual switch"
    $form.Size = New-Object System.Drawing.Size(300,200)
    $form.StartPosition = 'CenterScreen'

    $okButton = New-Object System.Windows.Forms.Button
    $okButton.Location = New-Object System.Drawing.Point(75, 120)
    $okButton.Size = New-Object System.Drawing.Size(75, 23)
    $okButton.Text="OK"
    $okButton.DialogResult = (System.Windows.Forms.DialogResult)::OK
    $form.AcceptButton = $okButton
    $form.Controls.Add($okButton)

    $cancelButton = New-Object System.Windows.Forms.Button
    $cancelButton.Location = New-Object System.Drawing.Point(150, 120)
    $cancelButton.Size = New-Object System.Drawing.Size(75, 23)
    $cancelButton.Text="Cancel"
    $cancelButton.DialogResult = (System.Windows.Forms.DialogResult)::Cancel
    $form.CancelButton = $cancelButton
    $form.Controls.Add($cancelButton)

    $label = New-Object System.Windows.Forms.Label
    $label.Location = New-Object System.Drawing.Point(10, 20)
    $label.Size = New-Object System.Drawing.Size(280, 20)
    $label.Text="Please select a virtual switch:"
    $form.Controls.Add($label)

    $listBox1 = New-Object System.Windows.Forms.ListBox
    $listBox1.Location = New-Object System.Drawing.Point(10, 40)
    $listBox1.Size = New-Object System.Drawing.Size(260, 20)
    $listBox1.Height = 80

    (void) $listBox1.Items.AddRange($Switches.Name)

    $form.Controls.Add($listBox1)

    $form.Topmost = $true

    $result = $form.ShowDialog()
    $SelectedSwitch = $listBox1.SelectedItem
}


#Part 2: Copy VHDX

$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.InitialDirectory = "F:\sysprepVHD\"
$openFileDialog.Filter = "VHDX files (*.vhdx)|*.vhdx"
$openFileDialog.Title = "Select the VHDX file"



if ($openFileDialog.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
    $SelectedFilePath = $openFileDialog.FileName
    
    $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
    $SaveFileDialog.InitialDirectory = "D:\"
    $SaveFileDialog.Filter = "VHDX files (*.vhdx)|*.vhdx"
    $SaveFileDialog.FileName = (System.IO.Path)::GetFileName($SelectedFilePath)

    if ($SaveFileDialog.ShowDialog() -eq (System.Windows.Forms.DialogResult)::OK) {
        $NewFolderPath = (System.IO.Path)::GetDirectoryName($SaveFileDialog.FileName)
        $NewFileName = (System.IO.Path)::GetFileName($SaveFileDialog.FileName)

        if (!
(Test-Path $NewFolderPath)) { New-Item -ItemType Directory -Path $NewFolderPath } $BufferSize = 1024 * 1024 $Buffer = New-Object byte() $BufferSize $SourceStream = (System.IO.File)::OpenRead($SelectedFilePath) $DestinationStream = (System.IO.File)::Create($NewFolderPath + "\" + $NewFileName) $BytesRead = 0 $TotalBytes = (System.Math)::Min($SourceStream.Length, (System.Int64)::MaxValue) $BytesCopied = 0 while (($BytesRead = $SourceStream.Read($Buffer, 0, $BufferSize)) -gt 0) { $DestinationStream. Write($Buffer, 0, $BytesRead) $BytesCopied += $BytesRead Write-Progress -Activity "Copying $SelectedFile" -PercentComplete ((System.Int32)(100 * $BytesCopied / $TotalBytes)) } $SourceStream. Close() $DestinationStream. Close() } } #Part 3: New-VM $VHDLocation = Split-Path -Path $DestinationStream.Name $VHDs = $DestinationStream.Name if ($result -eq (System.Windows.Forms.DialogResult)::OK) { New-VM -Name $VMName -MemoryStartupBytes $VMMemoryStartupBytes -Generation 2 -Path $VHDLocation -SwitchName $SelectedSwitch -VHDPath $VHDs Set-VM -Name $VMName -ProcessorCount $VMProcessorCount Start-VM -Name $VMName }

런타임에 머신 이름, 코어 정해진


램. 정해진


스위치 정해진


길에서 VHDX 정해진


VHDX 컴퓨터에 저장 목표 노선 정해진


복사 진전 (참고 파워쉘 ISE가다 빠른.)


VM생산하는 그리고 시작하다 확인


이 시간 메일에서 열기, 저장 ~에서 대화~에서 원래 배우다 숫자 있었다.