Tuncay Sahin

ICT Engineer | Docent ICT & Trainer

In this document you will find Hyper-V Administration cmdlets.

 

To view cmdlets for Hyper-V

Get-Command -Module Hyper-V

Create a new vm with new vhd

New-VM [[-Name] <String> ] [[-MemoryStartupBytes] <Int64> ] -NewVHDPath <String> -NewVHDSizeBytes <UInt64> [-AsJob] [-BootDevice <BootDevice> ] [-ComputerName <String[]> ] [-Path <String> ] [-SwitchName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Create a new vm with existing vhd

New-VM [[-Name] <String> ] [[-MemoryStartupBytes] <Int64> ] -VHDPath <String> [-AsJob] [-BootDevice <BootDevice> ] [-ComputerName <String[]> ] [-Path <String> ] [-SwitchName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

creates a virtual machine named new 2 that has 1 GB of memory and that is connected to a new 40 GB virtual hard disk

New-VM –Name "new 2" –MemoryStartupBytes 1GB –NewVHDPath d:vhdbase.vhdx

Start VM

Start-VM [-Name] <String[]> [-AsJob] [-ComputerName <String[]> ] [-Passthru] [ <CommonParameters>]

Stop VM

Stop-VM [-Name] <String[]> [-AsJob] [-ComputerName <String[]> ] [-Force] [-Passthru] [-Save] [-TurnOff] [-Confirm] [-WhatIf] [ <CommonParameters>]

Add a virtual DVD drive using file D:ISOsdisc1.iso to virtual machine Test

Add-VMDvdDrive -VMName Test –Path D:ISOsdisc1.iso

Adds a hard disk drive to a virtual machine

Add-VMHardDiskDrive [-VMName] <String[]> [[-ControllerType] <ControllerType> ] [[-ControllerNumber] <Int32> ] [[-ControllerLocation] <Int32> ] [[-Path] <String> ] [-AllowUnverifiedPaths] [-ComputerName <String[]> ] [-DiskNumber <UInt32> ] [-Passthru] [-ResourcePoolName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Creates a snapshot of a virtual machine

Checkpoint-VM [-Name] <String[]> [[-SnapshotName] <String> ] [-AsJob] [-ComputerName <String[]> ] [-Passthru] [ <CommonParameters>]

Exports a virtual machine to disk.

Export-VM [-Name] <String[]> [-Path] <String> [-AsJob] [-ComputerName <String[]> ] [-Passthru] [ <CommonParameters>]

Exports a snapshot as a virtual machine (VM) and writes it to disk

Parameter Set: SnapshotName

Export-VMSnapshot [-Name] <String[]> [-Path] <String> -VMName <String[]> [-AsJob] [-ComputerName <String[]> ] [-Passthru] [-Confirm] [-WhatIf] [ <CommonParameters>]

Retrieves a VMObject for each virtual machine (VM) on the Hyper-V host.

Get-VM [[-Name] <String[]> ] [-ComputerName <String[]> ] [ <CommonParameters>]

 

Get-VM –ComputerName Server1 | Where-Object {$_.State –eq ‘Running’}

Imports a virtual machine from a file.

Import-VM [-Path] <String> [[-VhdDestinationPath] <String> ] -Copy [-AsJob] [-ComputerName <String[]> ] [-GenerateNewId] [-SmartPagingFilePath <String> ] [-SnapshotFilePath <String> ] [-VhdSourcePath <String> ] [-VirtualMachinePath <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Imports the virtual machine from its configuration file. The virtual machine is registered in-place, so its files are not copied.

Import-VM –Path ‘D:TestVirtualMachines5AE40946-3A98-428E-8C83-081A3C6BD18C.XML’

Imports the virtual machine by copying its files to the default virtual machine and virtual hard drive storage locations of the Hyper-V host. The imported virtual machine will be given a new unique identifier, not the one in the configuration file. This is useful when you want to import multiple copies of a virtual machine, since each virtual machine must have a unique identifier.

Import-VM -Path ‘D:Test2Virtual Machines8F148B6D-C674-413E-9FCC-4FBED185C52D.XML’ –Copy –GenerateNewId

Mounts one or more virtual hard disks (VHDs) specified by one or more virtual hard disk (VHD) files.

Mount-VHD [-Path] <String[]> [-ComputerName <String[]> ] [-NoDriveLetter] [-Passthru] [-ReadOnly] [ <CommonParameters>]

Creates one or more new virtual hard disks

New-VHD –Path c:Base.vhdx –SizeBytes 10GB

Deletes a virtual machine

Remove-VM [-Name] <String[]> [-AsJob] [-ComputerName <String[]> ] [-Force] [-Passthru] [-Confirm] [-WhatIf] [ <CommonParameters>]

Resize virtual hard disk

Resize-VHD [-Path] <String[]> [-SizeBytes] <UInt64> [-AsJob] [-ComputerName <String[]> ] [-Passthru] [-Confirm] [-WhatIf] [ <CommonParameters>]

Restart a virtual machine

Restart-VM [-Name] <String[]> [-AsJob] [-ComputerName <String[]> ] [-Force] [-Passthru] [ <CommonParameters>]

Meer informatie

Voor meer informatie of voor een persoonlijk adviesgesprek kunt u altijd vrijblijvend contact met mij opnemen.

E-Mail

info@tuncaysahin.nl