This is a sample script that is written in the Mirage PowerCLI. It details the procedure for provisioning pending devices in the Mirage PowerCLI.

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

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

"----------Get-MirageVolume---------"
$volume = Get-MirageVolume $volumename | Select-Object -First 1
if (!$volume)
{
	"Can not get volume with name $volumename."
	return
}
$volume

"----------Get-MiragePolicy---------"
$policy = Get-MiragePolicy $policyname | Select-Object -First 1
if (!$policy)
{
	"Can not get policy with name $policyname."
	return
}
$policy

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

"------Get-MiragePendingDevice------"
$device = Get-MiragePendingDevice | Select-Object -First 1
if (!$device)
{
	"There's no pending device on Mirage server."
	return
}
$device

"-----------ProvisionFlow-----------"
$cvd = $device | New-MirageCvd -Policy $policy -Volume $volume -BaseLayer $baselayer -Domain $domain -User $domainuser -Password $domainpassword -Provision -Force
if(!$cvd)
{
	"Provision flow fails"
	return
}

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