Its been a while with no updates and it's not that I haven't been working hard, it's that I have been doing a lot of stuff directly with the API of systems like WHMCS or NetBox, which have an extremely low appeal to anyone not working in the service provider space, so haven't been adding it all to the blog. If anyone wants me to add this stuff please just get in touch and I will put it on.
I was recently asked to create a function that would allow you to set the IP address of a virtual machine from the host in a Hyper-V environment.
Getting this working for Windows was pretty easy:
function Set-VMIp {
param(
$VMhost,
$VMname,
$Mask,
$GateW,
$IPaddress
)
Invoke-Command -ComputerName $VMhost -ArgumentList $IPaddress, $Mask, $Gatew, $VMname -ScriptBlock {
[string]$VMname = $args[3]
$VMManServ = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService
$vm = Get-WmiObject -Namespace 'root\virtualization\v2' -Class 'Msvm_ComputerSystem' | Where-Object { $_.ElementName -eq $VMname }
$vmSettings = $vm.GetRelated('Msvm_VirtualSystemSettingData') | Where-Object { $_.VirtualSystemType -eq 'Microsoft:Hyper-V:System:Realized' }
$nwAdapters = $vmSettings.GetRelated('Msvm_SyntheticEthernetPortSettingData')
$ipstuff = $nwAdapters.getrelated('Msvm_GuestNetworkAdapterConfiguration')
$ipstuff.DHCPEnabled = $false
$ipstuff.DNSServers = "8.8.8.8"
$ipstuff.IPAddresses = $args[0]
$ipstuff.Subnets = $args[1]
$ipstuff.DefaultGateways = $args[2]
$setIP = $VMManServ.SetGuestNetworkAdapterConfiguration($VM, $ipstuff.GetText(1))
}
}
I can't really claim this as all being my own work, I used a blog post from a Microsoft employee, head of product dev or something or other. Unfortunately, I can't seem to source the link right now to give proper credit. You dont really need to see it though. His post was pretty hardcore and mine is much easier, I promise.
'IT이야기 > Hyper-V' 카테고리의 다른 글
SCVMM 오류 12711. 클러스터 리소스를 찾을 수 없습니다(0x138F). (0) | 2022.12.07 |
---|---|
Hyper-V 인증서는 30일 이내에 만료됩니다. (0) | 2022.12.07 |
PowerShell, Hyper-V: List clustered VMs with mounted ISO, then dismount them all. (0) | 2022.11.29 |
Windows Storage spaces S2D(3Node) (0) | 2022.11.29 |
Fault tolerance and storage efficiency on Azure Stack HCI and Windows Server clusters (0) | 2022.11.29 |