PowerShell script that uses the Tintri Toolkit APIs to move VMs from a Tintri Global Center (TGC) to another destination

# Import the Tintri Toolkit module
Import-Module -Name Tintri.Powershell.Toolkit

# Connect to the Tintri Global Center
Connect-TintriServer -Server <TGC_IP> -Credential (Get-Credential)

# Specify the source TGC VMstore name
$sourceVMstore = "<Source_VMstore_Name>"

# Specify the destination TGC VMstore name
$destinationVMstore = "<Destination_VMstore_Name>"

# Get the list of VMs from the source VMstore
$sourceVMs = Get-TintriVM -VMstoreName $sourceVMstore

# Loop through and move VMs to the destination VMstore
foreach ($sourceVM in $sourceVMs) {
    $sourceVMName = $sourceVM.vmName

    # Get the VM details from the source VMstore
    $sourceVMDetails = Get-TintriVM -VMstoreName $sourceVMstore -Name $sourceVMName

    # Create a clone of the VM on the destination VMstore
    $destinationVMDetails = New-TintriVM -VMstoreName $destinationVMstore -Name $sourceVMName -SourceVM $sourceVMDetails

    # Start the clone operation
    Start-TintriVM -VMstoreName $destinationVMstore -Name $sourceVMName

    # Wait for the clone operation to complete
    do {
        Start-Sleep -Seconds 10
        $cloneStatus = Get-TintriVMCloneStatus -VMstoreName $destinationVMstore -Name $sourceVMName
    } while ($cloneStatus -eq "Cloning")

    # Check if the clone operation was successful
    if ($cloneStatus -eq "Success") {
        Write-Host "VM '$sourceVMName' has been successfully moved to '$destinationVMstore'."
    } else {
        Write-Host "Failed to move VM '$sourceVMName' to '$destinationVMstore'."
    }
}

# Disconnect from the Tintri Global Center
Disconnect-TintriServer

Make sure to replace “, “, and “ with the actual IP address of your Tintri Global Center, the name of the source VMstore, and the name of the destination VMstore, respectively. Please note that this script assumes you have the Tintri PowerShell Toolkit module installed and properly configured.

Leave a comment