PowerCLI

  • 1.  export resource pools from one cluster to another

    Posted 5 days ago

    HI

    I have 2 clusters one cluster is with old hosts and we just provisioned new hosts but need to copy all resource pools from one cluster to another in the same datacentre

    Exporting is easy

    #Export Resource Pool Structure
    #By https://communities.vmware.com/message/2344027
    Connect-VIServer -Server king-vcenter-01.scc-zip.net -Protocol https -User dalibor.bosic@ziptel.ca -Password rikoLA!123
    $clusterName = "Mtl1-G8"
    $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:\vspherescripts\scriptsoutput\montrealpools.csv -NoTypeInformation -UseCulture

    But I cannot import these resource pools into another cluster with the same values it says that cluster doesnt exist although it is created in vcenter under same datacentre

    How would i import. Export gives me nice csv file but cannot import



  • 2.  RE: export resource pools from one cluster to another

    Posted 5 days ago

    Without seeing the code you use to import it is hard to tell what could go wrong.

    PS: not sure you want to publish the credentials for your vCenter on here



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


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


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



  • 3.  RE: export resource pools from one cluster to another

    Posted 5 days ago

    HI I was playing with it a bit and came up with this

    #Export Resource Pool Structure
    #By https://communities.
    $clusterName = "clusterA"
    $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:\storagemigrate\montrealpools.csv -NoTypeInformation -UseCulture

    Couldnt figure out how to do it automatically so did little bit of manual work and then import function

    I went to csv file and put new cluster name for example clusterB

    then execute this

    foreach($row in (Import-Csv C:\storagemigrate\montrealpools.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
          }
        }
      }
    }

    This actually copies all resource pools with the same name. I hoped it will keep resource pools settings but it didnt however good thing is that only one or 2 resporce pools have changed settings so that will work out even if i have to change them manually