PowerCLI function Change-Mac

As we needed to change a lot of MAC addresses because we needed to move a lot of VM’s to another vCenter. I created a function to change the MAC-Address of a VM trough PowerCLI.
Because the address is based on the vCenter ID we had some troubles in the past with SCCM and double MAC Addresses so we needed to take this opportunity to fix it to be compliant with the vCenter ID.

function Change-Mac{
Generates a new Mac-Address based on the existing vCenter ID
This function creates a new MAC Address while the NIC
configuration is maintained
Source: The Interwebz
Authors: Me, Myself and I
Specify the virtual machine to change the MAC Address from
PS> Change-Mac -VM VM001
PS> (GC import.txt)|change-mac
Param (
Valuefrompipeline = $true,
ParameterSetName = "VM",
Mandatory = $true,
HelpMessage = "Enter VM name")]

foreach ($vmnic in $VM){
$objState = Get-VM $vmnic | Select-Object PowerState}
If ($objState -match "off")
$thisAdapter = Get-NetworkAdapter -Vm $vmnic
foreach ($nic in $thisAdapter)
$nic.ExtensionData.AddressType = "Generated"
$nic.ExtensionData.MacAddress = ""
Set-NetworkAdapter $thisAdapter -confirm:$false
Write-Host -ForegroundColor Green $vmnic "succesfully edited"
Write-Host -ForegroundColor red $vm "is not powered off, please turn off!"

Windows Boot Configuration Data

Administrative privileges are required to use BCDEdit to modify BCD.

Boot Configuration Data (BCD) files provide a store that is used to describe boot applications and boot application settings. The objects and elements in the store effectively replace Boot.ini.
/timeout Specifies the time to wait, in seconds, before the boot manager selects the default entry.

Set the timeout to 5 seconds.

bcdedit /timeout 5