Skip to content

Instantly share code, notes, and snippets.

@pablitocli
Created February 25, 2019 03:17
Show Gist options
  • Save pablitocli/11fb246332f31c8696695e4f8f90f5fc to your computer and use it in GitHub Desktop.
Save pablitocli/11fb246332f31c8696695e4f8f90f5fc to your computer and use it in GitHub Desktop.
WRITE-HOST "!!!RESCATANDO LOS VMK!!!"
$VMKid=READ-HOST "Ingresar el nombre del VMKERNEL - Input the VMKERNEL Name"
$Destination=READ-HOST "A que VSWITCH desea mover el VMK?? - What VSWITCH wants to move the VMK?"
$vmk=get-vmhost | get-vmhostnetworkadapter -name $vmkid
$ip=$vmk.ip
$mask=$vmk.subnetmask
$mtu=$vmk.mtu
$porgroupname=$vmk.PortGroupName
$mgmtstate=$vmk.ManagementTrafficEnabled
$vmotion=$vmk.VMotionEnabled
$vsan=$vmk.VMotionEnabled
$ft=$vmk.FaultToleranceLoggingEnabled
$vlanid=get-vmhost | get-virtualportgroup -name $porgroupname | select vlanid
if ($porgroupname -eq "Management Network" -and $mgmtstate -eq "$true"){
$chekvmkmgmt=get-vmhost | Get-VMHostNetworkAdapter | where {$_.ManagementTrafficEnabled -eq $true}
if($chekvmkmgmt.count -eq "1") {WRITE-HOST "ESTE SCRIPT NO MOVERA EL VMK DE MGMT, SIN TENER UN MGMT TEMPORAL. - THIS SCRIPT DOESN´T MOVE THE MGMT VMKWENEL, WITHOUT A TEMPORAL MGMT"}}
Else
{
get-vmhost | get-vmhostnetworkadapter -name $vmk | remove-vmhostnetworkadapter -confirm:$false
get-vmhost | get-virtualportgroup -name $porgroupname | Remove-VirtualPortGroup -confirm:$false
$vswitch= get-vmhost | get-virtualswitch -name *$destination*
get-vmhost | New-VMHostNetworkAdapter -VirtualSwitch $vswitch -PortGroup $porgroupname -ip $ip -SubnetMask $mask -ManagementTrafficEnabled $mgmtstate -VMotionEnabled $vmotion -VsanTrafficEnabled $vsan -FaultToleranceLoggingEnabled $ft -confir:$false
get-vmhost | get-virtualportgroup -name $porgroupname | set-virtualportgroup -vlanid $vlanid.vlanid
}
$TASKCHECK= Get-virtualportgroup -name $name| get-virtualswitch
IF ($taskcheck.name -like $vswitch){write-host "!!!EL VMKERNEL FUE MOVIDO SATISFACTORIAMENTE - THE VMKERNEL WAS MOVED SUCCESULLY!!"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment