Computer >> คอมพิวเตอร์ >  >> ระบบเครือข่าย >> ระบบเครือข่าย

การสร้างเครื่องเสมือนใน Hyper-V 2019 โดยใช้ PowerShell

ดังที่เราได้กล่าวไปแล้วในบทความก่อนหน้านี้ เครื่องเสมือนสามารถสร้างได้โดยใช้ GUI (Graphical User Interface) หรือ PowerShell ในกรณีส่วนใหญ่ ซึ่งทั้งสองตัวเลือกพร้อมใช้งาน ผู้ดูแลระบบไอทีต้องการใช้ GUI

ในบทความนี้ เราจะแสดงวิธีสร้างเครื่องเสมือนใน Hyper-V 2019 โดยใช้ PowerShell อย่างที่คุณอาจทราบแล้ว PowerShell เป็นเครื่องมือที่รวมเข้ากับระบบปฏิบัติการ Windows Clients และ Windows Servers ประกอบด้วย cmdlet หลายพันรายการที่ใช้ในการเรียกใช้คำสั่งเฉพาะ

และเช่นเคย เพื่อที่จะอธิบายขั้นตอน เราจะสร้างสถานการณ์จำลอง เรากำลังเรียกใช้ Hyper-V 2019 เป็นบทบาทบน Windows Server 2019 เราต้องการสร้างเครื่องเสมือนที่จะโฮสต์ Windows Server 2019 และมี RAM 8 GB และพื้นที่ดิสก์ 50 GB เริ่มกันเลย

  1. คลิกซ้าย บน เมนูเริ่ม และพิมพ์ PowerShell
  2. คลิกขวา บน PowerShell แล้วคลิก เรียกใช้ในฐานะผู้ดูแลระบบ
  3. คลิก ใช่ เพื่อยืนยันการเรียกใช้ PowerShell ในฐานะผู้ดูแลระบบ
  4. พิมพ์ คำสั่งด้านล่างลงใน PowerShell แล้วกด Enter เพื่อสร้างเครื่องเสมือน คุณจะต้องกำหนดชื่อเครื่องเสมือนและตำแหน่งที่คุณต้องการจัดเก็บ ในกรณีของเรา ชื่อคือ WinSrv2019 และตำแหน่งอยู่บนพาร์ติชัน E:\VirtualMachines\.
    New-VM -Name WinSrv2019 -MemoryStartupBytes 8GB -BootDevice VHD -NewVHDPath 
    
    E:\VirtualMachines\WinSrv2019.vhdx -Path E:\VirtualMachines -NewVHDSizeBytes 50GB -Generation 2 -Switch LAN
  5. การสร้างเครื่องเสมือนใน Hyper-V 2019 โดยใช้ PowerShell
  6. เพื่อให้เข้าใจคำสั่งที่เราดำเนินการ เรามาอธิบายสั้นๆ ว่ามันหมายถึงอะไร:
    -New-VM – used to create a new virtual machine.
    
    -Name WinSrv2019 – used o define the name of the virtual machine. In our case the name is WinSrv2019
    
    -MemoryStartupBytes 8 GB – assigned RAM memory to the virtual machine
    
    -BootDevice VHD -NewVHDPath E:\VirtualMachines\WinSrv2019.vhdx – used to create a new virtual hard disk (*.vhdx) on the certain location and declare it as a boot device
    
    -Path E:\VirtualMachines -NewVHDSizeBytes 50GB – used to define the location where we will store newly created disk and what is total capacity. In this case, the capacity is 50 GB.
    
    Generation 2 – define if we will use Generation 1 or Generation 2 VMs. Nowadays it is recommended to use Generation 2.
    
    -Switch LAN – used to define which virtual network switch will be assigned to the virtual machine. In our case the name of the virtual switch is LAN. In the previous article, we explained what are virtual network switches and how to create them. Please check it on the link.
  7. เพื่อแมปไฟล์ ISO กับไดรฟ์ CD/DVD ของ VM เพื่อติดตั้งระบบปฏิบัติการ คำสั่งคือ
    Add-VMDvdDrive -VMName WinSrv2019 -Path E:\Software\ISO\WinSrv2019.iso

    การสร้างเครื่องเสมือนใน Hyper-V 2019 โดยใช้ PowerShell

  8. เพื่อให้เข้าใจคำสั่งที่เราดำเนินการ ให้อธิบายสั้น ๆ ว่ามันหมายถึงอะไร:
    Add-VMDvdDrive – create new DVD Drive that will be used as the bootable drive
    
    VMName WinSrv2019 – choose the virtual machine where you would like to add a new DVD drive. In our case the name of the virtual machine is WinSrv2019
    
    -Path E:\Software\ISO\WinSrv2019.iso – choose the location where your ISO file is stored. Please note that you need to download ISO file from the official Microsoft or Linux website and then use it as installation media.
  9. เริ่มเครื่องเสมือนโดยพิมพ์คำสั่งด้านล่าง:
    Start-VM -Name WinSrv2019

    การสร้างเครื่องเสมือนใน Hyper-V 2019 โดยใช้ PowerShell

  10. พิมพ์ VMConnect.exe เพื่อเริ่ม Virtual Machine Connect . เครื่องมือ VMConnect ใช้เพื่อเชื่อมต่อกับเครื่องเสมือน
  11. เลือก เซิร์ฟเวอร์ และ เครื่องเสมือน แล้วคลิก ตกลง . ในกรณีของเรา Server เป็น localhost และเครื่องเสมือนคือ WinSrv2019 การสร้างเครื่องเสมือนใน Hyper-V 2019 โดยใช้ PowerShell