My PowerShell Commands to manage Hyper-V

Some PowerShell commands to manage Hyper-V.

Commands

Hyper-V

PowerShell Direct to manage Virtual Machine

PS C:\Users\Administrator> Enter-PSSession -VMName VM_Name

Create private VMSwitch

PS C:\Users\Administrator> New-VMSwitch -Name "Switch" -SwitchType Private

Create Internat VMSwitch

PS C:\Users\Administrator> New-VMSwitch -Name "Switch" -SwitchType Internal

Create External VMSwitch

PS C:\Users\Administrator> New-VMSwitch -Name "Switch" -AllowManagementOS $true -NetAdapterName 'NIC01'

List VMSwitch

PS C:\Users\Administrator> Get-VMSwitch

Delete VMSwitch

PS C:\Users\Administrator> Remove-VMSwitch -Name "Switch" -Force

Get VM informations

PS C:\Users\Administrator> Get-VM

Get VM version

PS C:\Users\Administrator> Get-VM | ft Name, Version

Update VM version

PS C:\Users\Administrator> Update-VmConfigurationVersion VM_Name

Create vhdx disk (Dynamic for thin provisionning or Fixed)

PS C:\Users\Administrator> New-VHD -Path D:\VM\VDISK01.vhdx -SizeBytes 10GB -Dynamic

Create Virtual Machine

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

Export Virtual Machine

PS C:\Users\Administrator> Export-VM -Name VM01 -Path D:\Export\VM01

Import Virtual Machine

PS C:\Users\Administrator> Import-VM -Path D:\Export\VM01

Group

Create new Virtual Machine Group

PS C:\Users\Administrator> New-VMGroup -Name GroupName -GroupType VMCollectionType

Rename Virtual Machine Group

PS C:\Users\Administrator> Rename-VMGroup -Name OldName -NewName NewName

List Virtual Machine Group

PS C:\Users\Administrator> Get-VMGroup

Add Virtual Machine to a group

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

Remove Virtual Machine Group

PS C:\Users\Administrator> $vm01 = Remove-VMGroup -Name VMGroup

Remove Virtual Machine from a Group

PS C:\Users\Administrator> $vm01 = Get-VM -Name VM01
PS C:\Users\Administrator> Remove-VMGroupMember -Name VMGroup -VM $vm01
Licence Creative Commons
Ce site http://shebangthedolphins.net est mis à disposition selon les termes de la licence Creative Commons Attribution
Contact :