-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyper-V CLI
75 lines (53 loc) · 1.84 KB
/
Hyper-V CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
List all VMs:
Get-VM
List powered on VMs:
Get-VM | where {$_.State -eq 'Running'}
List powered off VMs:
Get-VM | where {$_.State -eq 'Off'}
Start selected VM:
Start-VM -Name 2virtual machine name"
Start all powered off VMs:
Get-VM | where {$_.State -eq 'Off'} | Start-VM
Shutdown all running VMs:
Get-VM | where {$_.State -eq 'Running'} | Stop-VM
Create snapshot of selected VM:
Get-VM -Name <"VM Name" | Checkpoint-VM -SnapshotName "Snapshot name"
Create a new VM:
$VMName = "VMNAME"
$VM = @{
Name = $VMName
MemoryStartupBytes = 2147483648
Generation = 2
NewVHDPath = "C:\Virtual Machines\$VMName\$VMName.vhdx"
NewVHDSizeBytes = 53687091200
BootDevice = "VHD"
Path = "C:\Virtual Machines\$VMName"
SwitchName = (Get-VMSwitch).Name
}
New-VM @VM
Remove VM with prompt:
Remove-VM "VM Name"
Export Singular VM:
Export-VM -Name "VM name" -Path "Destination"
Export all VM:
Get-VM | Export-VM -Path "Destination"
Import VM and keep location:
Import-VM -Path ""Path""VM ID".vmcx"
Import and copy files to Host VM path.
C:\> Import-VM -Path ""Path""VM ID".vmcx" -Copy -GenerateNewId
List information about a vhd:
Get-VHD -Path "Source Folder Path and File"
List information about vhd(s) attatched to VM:
Get-VM -VMName "VM Name" | Select-Object -Property VMId | Get-VHD
Create dynamic VHD:
New-VHD -Path ""Destination""filename".vhd[x]" or .vhd"c:\Base.vhdx -SizeBytes 10GB
Create a static vhd:
New-VHD -Path ""Path""filename".vhd[x] -Fixed -SourceDisk 2 -SizeBytes 1TB
Convert VHD to VHDX:
Convert-VHD -Path "Source Folder Path and File" -DestinationPath "Destination Folder Path and File"
Exspand VHD to 1TB:
Resize-VHD -Path ""path""filename".vhd" -SizeBytes 1099511627776
change vhdx size:
Resize-VHD -Path ""path""filename".vhdx" -SizeBytes 20GB
Shrink vhdx:
Resize-VHD -Path ""path""filename".vhdx"x -ToMinimumSize