vCenter Migration

How to Migrate ESXi Host and VMs from one vCenter to new vCenter?


In this post we would see how to migrate Host and VMs from one vCenter to another.
While migrating VMs it’s important to maintain the VM Folder structure and Resource Pool structure, Retain user’s vCenter permissions.

Also there should not be any downtime for any VMs, Host or end-users should not face any issues while accessing VMs from VM Console or remotely once migration is completed.

Many Power CLI script mentioned in these post are not completely written by me, where possible I have given reference to original script write posts.
I have modified these script as per my requirements and where needed I have created new scripts.

I tried my best to share my experience by providing step by step guide how I migrated my vCenter Host, VMs and give back to community. Again you may have different setup, so not necessary these all steps would work for you so I would suggest you to test these script before using it in production.


My Setup

 

Currently I have three different vCenter servers running -
  • vCenter Server 4 with 28 ESXi 4.1 and 3154 VMs 
       This vCenter had one more Cluster which was used for VMware lab manager, so we couldn’t upgrade this vCenter. Finally lab manager is decommissioned.
  • vCenter Server 5.5 with 33 ESXi and 2700 VMs
  • vCenter 6.0 – At the end above two vCenter Host and VMs would be migrated to this vCenter and later on this vCenter would be also used for vCAC/vRealize automation.
These all Hosts and VMs are being used by Development Team, that’s why VM and template count is high. ESXi Host are using UCS B series servers with 512 GB of RAM.

As we cannot directly upgrade ESXi Host from version 4 to 6, we have to first migrate all Host to vCenter 5.5


vCenter Migration Steps

  1. Convert VM Templates to ‘VM’ & export Template list.
  2. Migrate ESXi Host and VMs from dvswitch to Standard switch
  3. Export all VMs list with Folder structure.
  4. Export Resource Pool structure.
  5. Export VMs with Resource pool.
  6. Export Resource Pools reservation and limits settings
  7. Export VMs notes, Custom attributes.  
  8. Export vCenter Roles and permissions.
  9. Migrate Host and VMs from old vCenter to new vCenter.
  10. Import Folder structure and Move VMs to its original folder.
  11. Import Resource Pools structure.
  12. Move VMs to its resource Pool.
  13. Import VM Notes and Custom attributes
  14. Import Resource Pools reservation, limits settings.
  15. Import vCenter permissions in new vCenter.
  16. Convert VM ‘Templates’ back to Templates.

All above task are performed using PowerCLI script, as I said some script I have taken from different forums and Blogs and I have created some scripts.

I have used all below scripts in real world, however I strongly recommend you understand each script and test it before using it in production environment.

So let’s start vCenter migration from 4.0 to 5.5


Step by Step vCenter Migration.


All below task need to be performed on old vCenter.


1. Convert VM Templates to ‘VM’ & export Template list.


First step is to convert all VM Template to VM, else during migration all template registration will be lost and you would have to manually browse datastores, browse template VM folder and add it to inventory in vCenter.
If you have 10/20 Templates then manual work can be done but think about 500+ VM Template.
Also while Vm templates are using dvswitch PortGroup, we cannot remove host form dvswitch.

…..updating script……..
…..updating script……..


2.  Migrate ESXi Host and VMs from dvswitch to Standard switch.

  • Fist export all dvswitch PortGroup with  VLAN ID
  • Create Standard switch and Port Groups on each Host.
  • Add Physical NIC to Standard switch.
  • Migrate VMs from dvswitch portgroup to stanadard switch Port Group
  • Migrate VMHost VMkernel PortGroups to standard switch
…..updating script……..
…..updating script……..
 

3.  Export all VMs list with Folder structure.

-----------------------------------------------------------------------------

#I have taken this script from below discussion
# By https://communities.vmware.com/message/1828708#1828708

New-VIProperty -Name 'BlueFolderPath' -ObjectType 'VirtualMachine' -Value {
    param($vm)

    function Get-ParentName{
        param($object)

        if($object.Folder){
            $blue = Get-ParentName $object.Folder
            $name = $object.Folder.Name
        }
        elseif($object.Parent -and $object.Parent.GetType().Name -like "Folder*"){
            $blue = Get-ParentName $object.Parent
            $name = $object.Parent.Name
        }
        elseif($object.ParentFolder){
            $blue = Get-ParentName $object.ParentFolder
            $name = $object.ParentFolder.Name
        }
        if("vm","Datacenters" -notcontains $name){
            $blue + "/" + $name
        }
        else{
            $blue
        }
    }

    (Get-ParentName $vm).Remove(0,1)
} -Force | Out-Null

$dcName = "vLAB_DC"

Get-VM -Location (Get-Datacenter -Name $dcName | Get-Cluster "vLAB_Cluster") |
Select Name, VMHost, BlueFolderPath |
Export-Csv "C:\vcenter-migration\vLAB-VMs-Folder.csv" -NoTypeInformation -UseCulture
-----------------------------------------------------------------------------



4.  Export Resource Pool structure.


-----------------------------------------------------------------------------
#Export Resource Pool Structure
#By https://communities.vmware.com/message/2344027

$clusterName = "vLAB_Cluster"
$cluster = Get-Cluster -Name $clusterName
Get-ResourcePool -Location $cluster |
Select Name,@{N="Parent";E={
  $path = $_.Parent.Name,$_.Name -join '/'
  $parent = $_.Parent
  while($parent -isnot [VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterIMpl]){
    $path = $parent.Parent.Name,$path -join '/'
    $parent = $parent.Parent
  }
  $path}} |
Export-Csv -path c:\vCenter-Migration\resource-pool.csv -NoTypeInformation -UseCulture


------------------------------------------------------------------------------


5.  Export VMs with Resource pool.


-----------------------------------------------------------------------------
$allvm = @()
$labvm = Get-Cluster "vLAB_Cluster" | Get-VM

foreach ( $vms in $labvm ) {

    $vm = " " | select Name, ResourcePool, ResourcePoolParent
       
            $vm.Name        = $vms.Name
            $vm.ResourcePool = $vms.ResourcePool
            $vm.ResourcePoolParent = $vms.ResourcePool.Parent                $allvm += $vm
            }
$allvm | select Name, ResourcePool, ResourcePoolParent | Export-Csv -NoTypeInformation -Path c:\vCenter-Migration\vms-with-resource-pool.csv

-----------------------------------------------------------------------------

6.  Export Resource Pools reservation and limits settings


-----------------------------------------------------------------------------
Get-Cluster "vLAB_Cluster" | Get-ResourcePool | where { $_.Name -ne "Resources" } |  select Name, Parent, CpuReservationMHz,  CpuLimitMHz, MemReservationMB,   MemLimitMB | Export-Csv -NoTypeInformation -Path c:\vCenter-Migration\resourcepool-settings.csv
-----------------------------------------------------------------------------


7.  Export VMs notes, Custom attributes.   


-----------------------------------------------------------------------------
 #Export Vms Notes, Custome attributes

$vmlist = Get-Cluster "vLAB_Cluster" | Get-VM
$Report =@()
    foreach ($vm in $vmlist) {
        $row = "" | Select Name, Notes, Key, Value, Key1, Value1, Key2, Value2, Key3, Value3, Key4, Value4
        $row.name = $vm.Name
        $row.Notes = $vm | select -ExpandProperty Notes
        $customattribs = $vm | select -ExpandProperty CustomFields
        $row.Key = $customattribs[0].Key
        $row.Value = $customattribs[0].value
        $row.Key1 = $customattribs[1].Key
        $row.Value1 = $customattribs[1].value  
        $row.Key2 = $customattribs[2].Key
        $row.Value2 = $customattribs[2].value
        $row.Key3 = $customattribs[3].Key
        $row.Value3 = $customattribs[3].value
        $row.Key4 = $customattribs[4].Key
        $row.Value4 = $customattribs[4].value
        $Report += $row
    }

$report | Export-Csv "c:\vCenter-Migration\vms-with-notes-and-attributes.csv" -NoTypeInformation

----------------------------------------------------------------------------- 



8.  Export vCenter Roles and permissions. 


-----------------------------------------------------------------------------
###
# Purpose        : Export vCenter roles and permissions to c:\vcenter-permissions.xml
# Created        : 18/08/2010
# Author         : VMware Community, namely Alan Renouf and Luc Dekens
# Pre-requisites : none
###

# Parameters
$OutputDir = "C:\vCenter-migration\"

# Root of the XML file
$global:vInventory = [xml]"<Inventory></Inventory>"

# Functions
function New-XmlNode{
    param($node, $nodeName)

    $tmp = $global:vInventory.CreateElement($nodeName)
    $node.AppendChild($tmp)
}

function Set-XmlAttribute{
    param($node, $name, $value)

    $node.SetAttribute($name, $value)
}
function Get-XmlNode{
    param ($path)
    $global:vInventory.SelectNodes($path)
}

function Get-Roles{
  begin{
    $authMgr = Get-View AuthorizationManager
    $report = @()
  }
  process{
    foreach($role in $authMgr.roleList){
      $ret = New-Object PSObject
      $ret | Add-Member -Type noteproperty -Name "Name" -Value $role.name
      $ret | Add-Member -Type noteproperty -Name "Label" -Value $role.info.label
      $ret | Add-Member -Type noteproperty -Name "Summary" -Value $role.info.summary
      $ret | Add-Member -Type noteproperty -Name "RoleId" -Value $role.roleId
      $ret | Add-Member -Type noteproperty -Name "System" -Value $role.system
      $ret | Add-Member -Type noteproperty -Name "Privilege" -Value $role.privilege
      $report += $ret
    }
  }
  end{
    return $report
  }
}
function Get-Permissions
{
  begin{
    $report = @()
    $authMgr = Get-View AuthorizationManager
    $roleHash = @{}
    $authMgr.RoleList | %{
      $roleHash[$_.RoleId] = $_.Name
    }
  }
  process{
    $perms = $authMgr.RetrieveAllPermissions()
    foreach($perm in $perms){
      $ret = New-Object PSObject
      $entity = Get-View $perm.Entity
      $ret | Add-Member -Type noteproperty -Name "Entity" -Value $entity.Name
      $ret | Add-Member -Type noteproperty -Name "EntityType" -Value $entity.gettype().Name
      $ret | Add-Member -Type noteproperty -Name "Group" -Value $perm.Group
      $ret | Add-Member -Type noteproperty -Name "Principal" -Value $perm.Principal
      $ret | Add-Member -Type noteproperty -Name "Propagate" -Value $perm.Propagate
      $ret | Add-Member -Type noteproperty -Name "Role" -Value $roleHash[$perm.RoleId]
      $report += $ret
    }
  }
  end{
    return $report
  }
}
$global:vInventory = [xml]"<Inventory><Roles/><Permissions/></Inventory>"

# Main
# Roles
  $XMLRoles = Get-XmlNode "Inventory/Roles"
Get-Roles | where {-not $_.System} | % {
  $XMLRole = New-XmlNode $XMLRoles "Role"
  Set-XmlAttribute $XMLRole "Name" $_.Name
  Set-XmlAttribute $XMLRole "Label" $_.Label
  Set-XmlAttribute $XMLRole "Summary" $_.Summary
  $_.Privilege | % {
    $XMLPrivilege = New-XmlNode $XMLRole "Privilege"
    Set-XmlAttribute $XMLPrivilege "Name" $_
  }
}

# Permissions
$XMLPermissions = Get-XmlNode "Inventory/Permissions"
Get-Permissions | % {
  $XMLPerm = New-XmlNode $XMLPermissions "Permission"
  Set-XmlAttribute $XMLPerm "Entity" $_.Entity
  Set-XmlAttribute $XMLPerm "EntityType" $_.EntityType
  Set-XmlAttribute $XMLPerm "Group" $_.Group
  Set-XmlAttribute $XMLPerm "Principal" $_.Principal
  Set-XmlAttribute $XMLPerm "Propagate" $_.Propagate
  Set-XmlAttribute $XMLPerm "Role" $_.Role
}

# Create XML file
$global:vInventory.Save($OutputDir + "vcenter-permissions.xml")
 

-----------------------------------------------------------------------------   
Apart from above script I will suggest you to export vCenter inventory using RVTools.
RVTools will help you to capture all details of Vm, host, virtual Networking, disk, storage. 

Let’s proceed to Host and VM Migration.


Migration Task 

 

9.  Migrate Host and VMs from old vCenter to new vCenter.


Assuming that you have completed all above pre-migration task. Now we can migrate all Host and VMs running it to new vCenter.
In this script we have to connect to both vCenter and perform migration task.

------------------------------------------------------------------------ #Host Migration - from old vCenter to new vCenter
#vCenter Migration Script

Disconnect-VIServer * -Confirm:$false

#Change to multi-mode vcenter management
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false


#Change source and destination vCenter Names
$src_vCenter = "vc01.corpdomain.local"
$dst_vCenter = "vlab-vc.corpdomain.local"

Write-Host 'Please enter user name password to connect both vCenter'
 #Enter vCenter administrator username/password when prompted


$creds = Get-Credential

$esxi_pass = 'password'

$cluster = "vLAB_Cluster"
#$dst_Cluster = "LAB_Cluster"

#$src_datacenter =
$dst_datacenter = "vLAB_DC"

#Connect vCenter servers

Write-Host "connecting vCenters......."
sleep 5

connect-viserver -server $src_vCenter -credential $creds
connect-viserver -server $dst_vCenter -credential $creds -NotDefault:$false

Write-Host "disbale HA on cluster"

#Disable HA on source vCenter Cluster
Get-Cluster $cluster -Server $src_vCenter  | Set-Cluster -HAEnabled:$false -Confirm:$false

Write-Host "Removing Hosts from source vCenter"

#Remove ESX hosts from old vcenter
$Myvmhosts = Get-Cluster $cluster -Server $src_vCenter | Get-VMHost
foreach ($vmhost in $Myvmhosts) {
Get-vmhost -Server $src_vCenter -Name $vmhost.Name | Set-VMHost -State "Disconnected" -Confirm:$false
Get-VMHost -server $src_vCenter -Name $vmhost.Name | Remove-VMHost -Confirm:$false
}

Write-Host "create Cluster on new vCenter"

#Create Cluster in New vCenter
New-Cluster -Name $cluster -Location ( Get-Datacenter $dst_datacenter) -Server $dst_vcenter -Confirm:$false

Write-Host "Add Hosts in new vCenter"

#add ESX hosts into new vcenter
foreach ($vmhost in $Myvmhosts) {
    Add-VMHost -Name $vmhost.name  -Location (Get-Cluster $cluster -server $dst_vCenter) -user root -Password $esxi_pass -Force
}

sleep 5

Write-Host "enabling HA and DRS on new Cluster"
#Turn on HA and DRS on
Set-Cluster -Server $dst_vCenter -Cluster $cluster -DrsEnabled:$true -HAEnabled:$true -Confirm:$false

Write-Host "disconnecting all vCenters"

Disconnect-VIServer * -Confirm:$false.


----------------------------------------------------------------------------- 


 Post migration Task

  We need to perform below task in new vCenter, considering you have migrate all Host and Vm to new vCenter.


10. Import Folder structure and Move VMs to its original folder.


Below script will create folder structure and move VMs to its own folder as it was in old vCenter.


-----------------------------------------------------------------------------  #Import Folders and Move VMs to its folder

$vmsonha5 = Get-Cluster vLAB_Cluster | Get-VM  |sort name
$csv3 = "C:\vCenter-Migration\vLAB_VMs_Folder.csv"

$newDatacenter = "RnDDataCenter5.x"
$newFolder = "vCenter-Folders"

$startFolder = New-Folder -Name $newFolder -Location (Get-Folder -Name vm -Location (Get-Datacenter -Name $newDatacenter))
$startfolder = Get-Folder "vCenter-Folders"

$testing2 = Import-Csv $csv3 -UseCulture

$testing2 | %{
    $location = $startFolder
    $_.BlueFolderPath.TrimStart('/').Split('/') | %{
        $tgtFolder = Get-Folder -Name $_ -Location $location -ErrorAction SilentlyContinue
        if(!$tgtFolder){
            $location = New-Folder -Name $_ -Location $location
        }
        else{
            $location = $tgtFolder
        }
    }
    
#     Write-Host $location
    $hm = $_.Name2
$wups = $vmsonha5 | where {$_.name -eq $hm}

#Write-Host $hm
Move-VM -VM $wups -Destination $location -Confirm:$false -RunAsync
    }


 -----------------------------------------------------------------------------

If your inventory is huge and if this script takes time to complete, I would suggest splitting VM csv file and running this same script in multiple sessions for each csv
This will help you to complete the task with less time.

E.g. in my activity each signal migration was taking 8 seconds to migrate each VM, then I divided exported csv and saved with 5 different names. Created 5 different copies of above script and executed in different in PowerCLI sessions, this helped me to reduce the migration time.


11. Import Resource Pools structure.

Import Resource Pool csv file and create resource Pools in new vCenter.

-----------------------------------------------------------------------------  
 #Import Resource Pool Structure
#By https://communities.vmware.com/message/2344027

foreach($row in (Import-Csv c:\vCenter-migration\resource-pool.csv -UseCulture)){
  $clusterName,$pools = $row.Parent.Split('/')
  Try {
    $skip = $false
    $location = Get-Cluster -Name $clusterName -ErrorAction Stop
  }
  Catch {
    "Cluster $clusterName not found"
    $skip = $true
  }
  if(!$skip){
    foreach($rp in $pools){
      Try {
        $location = Get-ResourcePool -Name $rp -Location $location -ErrorAction Stop
      }
      Catch {
        $location = New-ResourcePool -Name $rp -Location $location
      }
    }
  }
}

-----------------------------------------------------------------------------   



12. Import Resource Pools reservation, limits settings.

Set resource pools CPU, memory reservation and limits.

-----------------------------------------------------------------------------   
#Import Resouce Pool Memory, CPU Reservation and Limits

$rssetings = Import-Csv c:\temp\resourcepool-settings.csv

foreach ( $rs in $rssetings ) {

$rss = Get-ResourcePool $rs.Parent | Get-ResourcePool $rs.Name
Set-ResourcePool -ResourcePool $rss -CpuReservationMhz $rs.CpuReservationMHz -CpuLimitMhz  $rs.CpuLimitMHz -MemLimitMB $rs.MemLimitMB -MemReservationMB $rs.MemReservationMB

}

----------------------------------------------------------------------------- 


13. Move VMs to its resource Pool.

Move Vms to its own resource pool as it was in old resource Pool.

----------------------------------------------------------------------------- 
 #Move Vms to its resource-pool

$cluster = "VLAB_Cluster"
$csv = import-csv "c:\vCenter-Migration\vms-with-resource-pool.csv"

$vmsonha5 = Get-Cluster $cluster | Get-VM | sort Name
$ha5rs = Get-Cluster $cluster | Get-ResourcePool

foreach ( $vm in $csv  ) {

if ( $vm.ResourcePool -ne "Resources" ) {

$myvm = $vmsonha5 | where { $_.Name -eq $vm.Name }
$myrs = $ha5rs | where { $_.Name -eq $vm.ResourcePool }

Move-VM -VM $myvm -Destination $myrs -Confirm:$false -RunAsync
  
}
}

----------------------------------------------------------------------------- 
  

14. Import VM Notes and Custom attributes

---------------------------------------------------------------------------------- 
 ##Import VM Custom Attributes and Notes
$vms = Import-Csv c:\vCenter-Migration\vms-with-notes-and-attributes.csv
 

foreach ($vm in $vms) {
        set-vm -vm $vm.Name -Description $vm.Notes -Confirm:$false
        Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Key -Value $vm.Value -confirm:$false
        Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Key1 -Value $vm.Value1 -confirm:$false
        Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Key2 -Value $vm.Value2 -confirm:$false
        Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Key3 -Value $vm.Value3 -confirm:$false
        Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Key4 -Value $vm.Value4 -confirm:$false
  
    }

---------------------------------------------------------------------------------- 
 

15. Import vCenter permissions in new vCenter.


---------------------------------------------------------------------------------- 
###
# Purpose        : Import vCenter roles and permissions into a new vCenter.
# Created        : 18/08/2010
# Author         : VMware Community, namely Alan Renouf and Luc Dekens
# Pre-requisites : Source file c:\vcenter-permissions.xml
###

# Functions
function New-Role
{
    param($name, $privIds)
    Begin{}
    Process{

        $roleId = $authMgr.AddAuthorizationRole($name,$privIds)
    }
    End{
        return $roleId
    }
}

function Set-Permission
{
param(
[VMware.Vim.ManagedEntity]$object,
[VMware.Vim.Permission]$permission
)
Begin{}
Process{
    $perms = $authMgr.SetEntityPermissions($object.MoRef,@($permission))
}
End{
    return
}
}

# Main
# Create hash table with the current roles
$authMgr = Get-View AuthorizationManager
$roleHash = @{}
$authMgr.RoleList | % {
    $roleHash[$_.Name] = $_.RoleId
}

# Read XML file
$XMLfile = “C:\vCenter-migration\vcenter-permissions.xml”
$vInventory = [xml]"<dummy/>"
$vInventory.Load($XMLfile)

# Define Xpaths for the roles and the permissions
$XpathRoles = “Inventory/Roles/Role”
$XpathPermissions = “Inventory/Permissions/Permission”

# Create custom roles
$vInventory.SelectNodes($XpathRoles) | % {
    if(-not $roleHash.ContainsKey($_.Name)){
        $privArray = @()
        $_.Privilege | % {
            $privArray += $_.Name
        }
        $roleHash[$_.Name] = (New-Role $_.Name $privArray)
    }
}

# Set permissions
$vInventory.SelectNodes($XpathPermissions) | % {
    $perm = New-Object VMware.Vim.Permission
    $perm.group = &{if ($_.Group -eq “true”) {$true} else {$false}}
    $perm.principal = $_.Principal
    $perm.propagate = &{if($_.Propagate -eq “true”) {$true} else {$false}}
    $perm.roleId = $roleHash[$_.Role]

    $EntityName = $_.Entity.Replace(“(“,“\(“).Replace(“)”,“\)”)
    $EntityName = $EntityName.Replace(“[","\[").Replace("]“,“\]”)
    $EntityName = $EntityName.Replace(“{“,“\{“).Replace(“}”,“\}”)

    $entity = Get-View -ViewType $_.EntityType -Filter @{“Name”=("^" + $EntityName + "$")}
    Set-Permission $entity $perm
}

----------------------------------------------------------------------------------  

This script will import vCenter Roles and provide permission to users on vCenter, Cluster, Host, resource Pool, Folder or Vm level as it was in old vCenter.


16. Convert VM ‘Templates’ back to Templates.

Convert Template Vms back to Templates which we converted to VM before starting vCenter migration. 

---------------------------------------------------------------------------------- 
 #Convert VMs to Template

$vmtemplates = Import-Csv c:\vCenter-Migration\VM-Template-List.csv

foreach ( $vm in $vmtemplates ) {

Get-VM -name $vm.Name | Set-VM -ToTemplate -Confirm:$false

}

---------------------------------------------------------------------------------- 
 

Post migration issues


1. Unable to power on VM or VM disconnected from Network.

If users revert VM to snapshot, users cannot power on VM and VMs disconnected from Network.
As these snapshots were taken while VMs were connected to dv Switch in old vCenter and that dvswitch does not exist anymore. So this is expected behaviour.
As workaround before user power on such VMs ‘snapshot reverted’ they have to edit VM settings and map the new Standard switch port group to VM network adapter.

2. VM deleted or lost during migration

VM cannot be lost or get deleting during migration from one vCenter to another.
As my virtual environment is big sometime if user don’t find their VM, they were thinking if loosing VM in migration. But it’s not true. You can prove it using above exported reports and RVTools report.

If you do not convert Templates to VM before migration, then templates would be lost from VM inventory as it was registered in old vCenter. In such case you would have to browse datastores for template folders and add it back to vCenter inventory.
You can automate it using powercli script.


Attachment


I have attached all above script to this post.

Completed


With this we have completed migration of Host and VMs from one vCenter to new vCenter.
After this you can perform your regular VMware task like VM deployment, clone or upgrading Host. 

If there is any question or suggestion about this post, please post it in comment section. 

-
vPRH

3 comments:

  1. Awesome scripts thank you for posting these. I am having trouble importing VMs to folders. The folder structure gets created fine but i get errors moving the VMs to them:

    At C:\Users\agibson\Desktop\VCenter6 Notes\Migration\scripts\sdcdev\importnotes.ps1:10 char:34
    + Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Key4 -Val ...
    + ~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

    Set-CustomField : The term 'Set-CustomField' is not recognized as the name of a cmdlet, function, script file, or
    operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
    again.
    At C:\Users\agibson\Desktop\VCenter6 Notes\Migration\scripts\sdcdev\importnotes.ps1:10 char:9
    + Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Key4 -Val ...
    + ~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Set-CustomField:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    any help is appreciated.

    ReplyDelete
  2. Nevermind. I found that the $wups is defined as
    $hm = $_.Name2
    $wups = $vmsonha5 | where {$_.name -eq $hm}

    Since there is no "Name2" i changed it to $hm = $_.Name
    and it works great now!

    ReplyDelete
  3. good to know it worked for you.

    ReplyDelete