A szolgáltatás tárolása a könyvtárban, valamint az ismételt telepítése a azt (parancsfájl)
Hatókör: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager
Egy telepített szolgáltatást a könyvtárban tárolják, és telepítse újra a könyvtárban tárolt szolgáltatáson. A szolgáltatást a könyvtárban tárolni, tárolja az összes virtuális gépet a könyvtárban; szolgáltatás a szolgáltatás definíció maradnak, és a szolgáltatás jelenik meg a könyvtárban. Újra tárolt szolgáltatás központi telepítése, a szolgáltatás minden virtuális gép központi telepítése a VMM környezetben.
A következő parancsfájl az összes virtuális gép lekérdezi a megadott szolgáltatás, és tárolja őket a könyvtárkiszolgálóra, az a legjobb minősítést. Után az összes, a virtuális gépek vannak tárolva, a parancsfájl lehetővé teszi a győződjön meg arról, hogy a szolgáltatás a könyvtárban tárolt felfüggesztése. Ezután a parancsfájl újratelepíti a szolgáltatás által a legjobban névleges gazdagép egyes a tárolt virtuális gépek telepítése. Szeretné a virtuális gépek egy adott gazdagép telepítése, ha a gazdagép neve a $VMHost változó is megadhat.
<#
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
}