Add the Multiple machines for the MCS Machine Catalog

1. Create the MCS type machine catalog

New-BrokerCatalog -name 'TestCatalog' -ProvisioningType 'MCS' -SessionSupport 'MuiltiSession' -PersistUserChanges 'onlocal'

2. Add the machine to MCS machine catalog

$password = "1qaz!QAZ"
$securepassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$ADAccount = New-AcctADAccount -IdentityPoolName MCS_catalog2 -Count 180 -OutVariable result -ADUserName "xfadministrator" -ADPassword $SecurePassword
$machines = $ADAccount.SuccessfulAccounts
Foreach($machine in $machines)
{
    $VMName = $machine | select ADAccountName       
    New-provVM -ProvisioningSchemeName "MCS_catalog2" -ADAccountName $VMName.ADAccountName    
    #$provVM = Get-provVM |select ADAccountName,VMId |Where-Object{$_.ADAccountName -like $VMName}    
    New-BrokerMachine -CatalogUid 6 -MachineName $VMName.ADAccountName 
}

3.Delete the machine from XenServer host

for ($i=0; $i -le 3600000; $i++)
{
        start-sleep -seconds 3
        $i
Connect-XenServer -url "http://10.150.182.76" -UserName "root" -Password "9JdUl63w3Unf" -NoWarnCertificates -SetDefaultSession

$myVms = Get-XenVM | select name_label| Where-Object {$_.name_label -like "fwmachine*"}
for($j = 0; $j -lt $myVms.length-1; $j++){ 
        $number1 = $myVms[$j].name_label.substring(9)
        $number2 = $myVms[$myVms.length-1].name_label.substring(9)
        if ($number1 -lt $number2){
            $delVm = $myVms[$j].name_label      
        }else{
            $delVm = $myVms[$myVms.length-1].name_label
        }  
             $delVm   
             Remove-XenVM -Name $delVm

      }
               
}

 4.Delete the vdisk from xenserver

Connect-XenServer -url "http://10.150.182.76" -UserName "root" -Password "9JdUl63w3Unf" -NoWarnCertificates -SetDefaultSession

Get-XenVDI -Name fwmachine* | Remove-XenVDI
原文地址:https://www.cnblogs.com/Lina-zhu/p/9115659.html