This articles describes a means by which vCommander® administrators can run a script to convert all deployment destinations to a specified disk format (thin, thick lazy zeros, thick eager zeros). 


Requirements


  

$vCommanderServer = 'your.vcommander.address'
$CredFile = 'C:\scripts\creds\superuser_cred.xml' #Encrypted Credential file to connect to vcommander
$desiredFormat = "THIN"
#$desiredFormat = "THICK_LAZY"
#$desiredFormat = "THICK_EAGER" 

$moduleName = "VCommanderRestClient"
If (-not (Get-Module -name $moduleName)) {
                Import-Module -Name $moduleName
} else {
                Remove-Module $moduleName
                Import-Module -Name $moduleName
}
$moduleName = "VCommander"
If (-not (Get-Module -name $moduleName)) {
                Import-Module -Name $moduleName
} else {
                Remove-Module $moduleName
                Import-Module -Name $moduleName
}

#Connecting to vCommander
$Global:SERVICE_HOST = $vCommanderServer
$Global:REQUEST_HEADERS =@{}
$Global:BASE_SERVICE_URI = $Global:BASE_SERVICE_URI_PATTERN.Replace("{service_host}",$Global:SERVICE_HOST)  
$cred = (New-DecryptCredential -keyFilePath $CredFile)       
$Global:CREDENTIAL = $cred
VCommander\Set-IgnoreSslErrors
Set-BaseServiceURI "https://$vCommanderServer/webservices/services/rest/v2"
Connect-Client | Out-Null

echo "Now connected to vCommander"

$offset = 0
$orgRefs = Get-OrganizationReferences -max 20 -offset $offset 
while($orgRefs.ManagedObjectReferenceCollection.ManagedObjectReferences.Count -gt 0) {
    foreach($orgRef in $orgRefs.ManagedObjectReferenceCollection.ManagedObjectReferences) {
        Start-Sleep 2 # 2 second sleep so we don't cause performance issues

        $destinations = Get-DeploymentDestinationsByOrg -orgid $orgRef.id
        foreach($destination in $destinations.DeploymentDestinationCollection.DeploymentDestinations) {
            if($destination.diskFormat -ne $desiredFormat) {
                $oldFormat = $destination.diskFormat
                $destination.diskFormat = $desiredFormat

                # Create a new object to update the destination
                $newDestination = New-Object PSObject
                Add-Member -InputObject $newDestination -MemberType NoteProperty -Name "VMWareDeploymentDestination" -Value $destination -Force
                try {
                    $updatedDD = Update-DeploymentDestination -id $newDestination.VMWareDeploymentDestination.id -updatedDeploymentDestination $newDestination
                    Write-Host "$($orgRef.displayName) - destination '$($destination.name)' was converted from $($oldFormat) to $($desiredFormat)"
                } catch {
                    $Exception = $_
                    Write-Host "$($orgRef.displayName) - error converting destination '$($destination.name)' from $($oldFormat) to $($desiredFormat) - $($Exception.ErrorDetails)"
                }
            } else {
                Write-Host "$($orgRef.displayName) - destination '$($destination.name)' was already set to $($desiredFormat)"
            }
        }
    }

    $offset = $offset + 20
    $orgRefs = Get-OrganizationReferences -max 20 -offset $offset 
}

  

vCommander Script


Download the script to the vCommander application server. Embotics recommends storing all scripts related to vCommander in a single location, using sub-folders to identify the functions of particular scripts. With the script extracted to the C drive, the file location should be be as follows:


  • c:\scripts\destinations\convert_disk.ps1

Extract the file to this location and use a text editor to edit the script to include the IP address or FQDN of your vCommander server, and the location of your encrypted credentials file. Next, choose the desired format for all destination by uncommenting only that format. By default, the script sets all destinations to THIN. To change to another format, add a hash at the beginning of the line for THIN, and remove the hash from the line for either THICK_LAZY or THICK_EAGER.

Important! Before running this script, which you do outside of vCommander, make sure you have a database backup and/or application server snapshot to which you can return in the event you need to do so.

See Also