My PowerShell Commands to manage Hyper-V

Some PowerShell commands to manage Hyper-V.

Main

PS C:\Users\Administrator> Enter-PSSession -VMName VM_Name
PS C:\Users\Administrator> New-VMSwitch -Name "Switch" -SwitchType Private
PS C:\Users\Administrator> New-VMSwitch -Name "Switch" -SwitchType Internal
PS C:\Users\Administrator> New-VMSwitch -Name "Switch" -AllowManagementOS $true -NetAdapterName 'NIC01'
PS C:\Users\Administrator> Get-VMSwitch
PS C:\Users\Administrator> Remove-VMSwitch -Name "Switch" -Force
PS C:\Users\Administrator> Get-VM
PS C:\Users\Administrator> Get-VM | ft Name, Version
PS C:\Users\Administrator> Update-VmConfigurationVersion VM_Name
PS C:\Users\Administrator> New-VHD -Path D:\VM\VDISK01.vhdx -SizeBytes 10GB -Dynamic
PS C:\Users\Administrator> $Params = @{
Path = 'D:\VM'
Name = 'VM01'
MemoryStartupBytes = (2 * 1Gb)
SwitchName = 'Switch'
Generation = '2'
NewVHDPath = 'D:\VM\VM01\VDISK01.vhdx'
NewVHDSizeBytes = (80 * 1Gb)
}
PS C:\Users\Administrator> $VM = New-VM @Params
PS C:\Users\Administrator> $ISOPath = "C:\Users\Administrator\Downloads\14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64.ISO"
PS C:\Users\Administrator> $DVD = Add-VMDvdDrive -VMName $VM.VMName -Path $ISOPath -Passthru
PS C:\Users\Administrator> Set-VMFirmware -VM $VM -FirstBootDevice $DVD
PS C:\Users\Administrator> Set-VMProcessor $VM.Name -Count 4
PS C:\Users\Administrator> Export-VM -Name VM01 -Path D:\Export\VM01
PS C:\Users\Administrator> Import-VM -Path D:\Export\VM01
PS C:\Users\Administrator> Start-VM -Name VM01

Group

PS C:\Users\Administrator> New-VMGroup -Name GroupName -GroupType VMCollectionType
PS C:\Users\Administrator> Rename-VMGroup -Name OldName -NewName NewName
PS C:\Users\Administrator> Get-VMGroup
PS C:\Users\Administrator> $vm01 = Get-VM -Name VM01
PS C:\Users\Administrator> $group1 = Get-VMGroup -Name VMGroup
PS C:\Users\Administrator> Add-VMGroupMember -VMGroup $group1 -vm $vm01
PS C:\Users\Administrator> $vm01 = Remove-VMGroup -Name VMGroup
PS C:\Users\Administrator> $vm01 = Get-VM -Name VM01
PS C:\Users\Administrator> Remove-VMGroupMember -Name VMGroup -VM $vm01

Snapshots

PS C:\Users\Administrator> Get-VMSnapshot -VMName <VMName> -ComputerName <Computer.name>| fl
PS C:\Users\Administrator> Get-VMSnapshot -VMName <VMName> -ComputerName <Computer.name>| Remove-VMSnapshot
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :