This is a sample script that is written in the Mirage PowerCLI. It details the procedure for assigning a base layer to a CVD in the Mirage PowerCLI.

param($server, $username, $password, $cvdname, $baselayername)

"--------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

"--------Set-MirageCvd -BaseLayer--------"
$cvd = Set-MirageCvd -CVD $cvd -BaseLayer $baselayer -IgnoreWarnings -Force -DownloadOnly
if (!$cvd)
{
	"Fail to start download base layer."
	return
}
$cvd

"--------Get-MirageAssignment--------"
$success = $false
$maxRetries = 10
$retryCount = 0
while (!$success)
{
	Start-Sleep -s 20
	$assignment = Get-MirageAssignment -CVD $cvd -TaskType 'DownloadOnlyBaseLayerAssignment'
	if($assignment)
	{
		$success = $true
	}
	else
	{
		$retryCount++
		if($retryCount -gt $maxRetries)
		{
			"Download only base layer assignment is not created, retry times: $retryCount"
			return
		}
	}
}
$assignment

"--------Apply-MirageAssignment--------"
$maxRetries = 100
$retryCount = 0
Apply-MirageAssignment -Assignment $assignment -Force
while($true)
{
	Start-Sleep -s 20
	$assignment = Get-MirageAssignment -CVD $cvd -Type 'BaseLayerAssignment'
	if($assignment)
	{
		if($assignment.Status -eq 'Failed')
		{
			"Assign base layer flow fails"
			return
		}
		if($assignment.Status -eq 'Completed')
		{
			Get-MirageCvd -Id $cvd.Id
			"Assign base layer flow succeeds."
			return
		}
	}
	$retryCount++
	if($retryCount -gt $maxRetries)
	{
		"Apply layer assignment is not created/completed, retry times: $retryCount"
		return
	}
}