Поделиться через


Служба хранилища в библиотеке и повторно развертывать его (скрипт)

 

Применимо к: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

Можно хранить развернутой службы в библиотеке и повторное развертывание хранимой службы из библиотеки. Чтобы сохранить службу в библиотеке, хранить все виртуальные машины для этой службы в библиотеке; Сохранить определение службы и службы отображается в библиотеке. Повторное развертывание хранимой службы, развертывание каждой виртуальной машины в службу для вашей VMM среды.

Отказ от ответственности

Следующий сценарий возвращает все виртуальные машины для указанной службы и сохраняет их на сервер библиотеки с высоким рейтингом. После все виртуальные машины хранятся сценария приостанавливается позволяет проверить, что служба хранятся в библиотеке. Затем сценарий выполняет повторное развертывание службы путем развертывания каждой из хранимых виртуальных машин для наилучшего номинальной узла. Если вы хотите развернуть виртуальные машины на определенном узле, можно указать это имя узла для переменной $VMHost.

  
<#  
  Description:   This script stores all of the virtual machines for the specified  
                 service to the best-rated library server. The script then pauses.  
                 When it resumes, the script re-deploys each of the virtual machines  
                 for the service to the best-rated host, thereby re-dedeploying the  
                 service.  
#>  
  
# Get the service you want to store in the library.  
$Service = Get-SCService -Name "Service01"  
  
# Get all the virtual mnachines for the service.  
$VMs = Get-SCVirtualMachine -Service $Service  
  
# Get the library server with the highest rating.  
$LibServers = @(Get-SCLibraryServer)  
$RatedLibServers = Get-SCLibraryRating -LibraryServer $LibServers | where {$_.Rating -gt 0} | sort -property rating -descending  
If ($RatedLibServers.Count -eq 0) {throw "No library servers meet the placement requirements."}  
$LibServer = $RatedLibServers[0].Library  
$SharePath = "\\$LibServer\Services"  
  
# Store all virtual machines in the service to the library server.  
ForEach ($VM in $VMs)  
{  
   If ($_.Status -eq "Running")  
   {  
      Stop-SCVirtualMachine -VM $VM  
   }  
  
   Else  
   {  
      Save-SCVirtualMachine -VM $VM -LibraryServer $LibServer -SharePath $SharePath -RunAsynchronously -JobVariable "StoringVMS"  
   }  
}  
  
# Display progress of storing virtual machines.  
While ($StoringVMs.status -eq "Running")  
{  
   Write-Progress -Activity "Storing virtual machines" -Status $StoringVMs.CurrentStep  
   Start-Sleep -Seconds 5  
}  
  
# Ensure that the service is stored in the library before continuing.  
While ($Service.DeploymentState -ne "Stored")  
{  
   Start-Sleep -Seconds 5  
}  
  
# Re-deploy the service.  
  
ForEach ($VM in $VMs)  
{  
   # Get the host with the highest rating for the virtual machine.  
   $VMHosts = Get-SCVMHost  
   $HostRatings = @(Get-SCVMHostRating -VMHost $VMHosts -VM $VM | where {$_.Rating -gt 0} | sort -Property Rating -Descending)  
   If ($HostRatings.Count -eq 0) {throw "No hosts meet the placement requirements."}  
   $VMHost = $HostRatings[0].vmhost  
  
   # Deploy the virtual machine.  
   Write-Host "Deploying virtual machine $VM on host $VMHost."  
   Move-SCVirtualMachine -VMHost $VMHost -VM $VM -Path "D:\VirtualMachinePath" -StartVMOnTarget -RunAsynchronously  
}