Set-HyperVHostMacRange
Hyper-V: Updates the dynamic MAC address pool range
#Requires -Version 5.1
#Requires -Modules Hyper-V
[CmdletBinding()]
Param (
[string]$ComputerName = "localhost",
[PSCredential]$Credential,
[Parameter(Mandatory = $true)]
[string]$MacAddressMinimum,
[Parameter(Mandatory = $true)]
[string]$MacAddressMaximum
)
Process {
try {
$params = @{
'ComputerName' = $ComputerName
'ErrorAction' = 'Stop'
}
if ($Credential) { $params.Add('Credential', $Credential) }
$setParams = @{ 'MacAddressMinimum' = $MacAddressMinimum; 'MacAddressMaximum' = $MacAddressMaximum; 'ErrorAction' = 'Stop' }
if ($Credential) { $setParams.Add('Credential', $Credential) }
else { $setParams.Add('ComputerName', $ComputerName) }
Set-VMHost @setParams
$updatedHost = Get-VMHost -ComputerName $ComputerName
$result = [PSCustomObject]@{
ComputerName = $updatedHost.ComputerName
MacAddressMinimum = $updatedHost.MacAddressMinimum
MacAddressMaximum = $updatedHost.MacAddressMaximum
Action = "MacRangeUpdated"
Status = "Success"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $result
}
catch {
throw
}
}Specifies the name of the Hyper-V host. Defaults to the local machine.
Specifies the credentials to use for the remote connection.
Specifies the minimum MAC address (e.g., "00155D000000").
Specifies the maximum MAC address (e.g., "00155DFFFFFF").