This is a sample script that is written the Mirage PowerCLI. It details the procedure for migrating an endpoint OS in the Mirage PowerCLI.

param($server, $username, $password, $cvdname, $baselayername, $domain, $domainuser, $domainpassword)

"--------Connect-MirageServer--------"
Connect-MirageServer $server $username $password -TrustUnknownCertificate

"--------Get-MirageCvd--------"
$cvd = Get-MirageCvd $cvdname | Select-Object -First 1
if (!$cvd)
{
	"Can not get cvd with name $cvdname."
	return
}
$cvd

"--------Get-MirageBaseLayer--------"
$baselayer = Get-MirageBaseLayer $baselayername | Select-Object -First 1
if (!$baselayer)
{
	"Can not get base layer with name $baselayername."
	return
}
$baselayer

"--------New-MirageOsMigration--------"
$migration = New-MirageOsMigration -CVD $cvd -BaseLayer $baselayer -Domain $domain -User $domainuser -Password $domainpassword -DownloadOnly -Force | Select-Object -First 1
if (!$migration)
{
	"Fail to start download only OS migration."
	return
}
$migration

"--------Wait for BI download complete--------"
$success = $false
$maxRetries = 100
$retryCount = 0
while (!$success)
{
	Start-Sleep -s 20
	$migration = Get-MirageOsMigration -Id $cvd.Id
	if($migration.Status -eq 'DownloadComplete')
	{
		$success = $true
	}
	elseif($migration.Status -eq 'DownloadCancelled')
	{
		"Download only migration cancelled"
		return
	}
	else
	{
		$retryCount++
		if($retryCount -gt $maxRetries)
		{
			"Download only migration is not completed, retry times: $retryCount"
			return
		}
	}
}
$migration


"--------Apply-MirageOsMigration--------"
$cvd = Apply-MirageOsMigration $migration
if(!$cvd)
{
	"Fail to apply download only migration."
	return
}

"OS migration starts"
$maxRetries = 100
$retryCount = 0
while ($true)
{
	Start-Sleep -s 20
	$assignment = Get-MirageAssignment -CVD $cvd -TaskType 'Migration'
	if($assignment)
	{
		if($assignment.Status -eq 'Failed')
		{
			"OS migration flow fails"
			return
		}
		if($assignment.Status -eq 'Completed')
		{
			Get-MirageCvd -Id $cvd.Id
			"OS migration flow succeeds."
			return
		}
	}
	$retryCount++
	if($retryCount -gt $maxRetries)
	{
		"Migration assignment is not created/completed, retry times: $retryCount"
		return
	}
}