다음을 통해 공유


확장 컴퓨터 계층 (스크립트)

 

적용 대상: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

서비스에서 확장 하 여 배포 된 서비스에서 사용 중인 리소스의 양을 줄일 수 있습니다. 서비스에서 크기를 조정 하는 컴퓨터 계층에서 가상 컴퓨터를 제거 하 하거나 가상 컴퓨터의 상태를 변경할 수 있습니다. 설정 하 여에서 컴퓨터 계층을 확장할 수 있는지 여부를 정의 하는 InstanceMinimumCount 컴퓨터 계층 템플릿에 대 한 매개 변수입니다.

이 항목의 스크립트는 두 매개 변수 집합을 포함합니다. 두 매개 변수 집합 서비스 및 컴퓨터 계층을 제공 해야 합니다. 그러나 가상 컴퓨터를 사용 하 여 제거할 수 있는지를 지정할 수는는 RemoveVM 스위치를 사용 하 여 가상 컴퓨터에서 작업을 수행 하거나는 VMAction 매개 변수입니다.

부인

다음 스크립트를 서비스에서에서 가상 컴퓨터를 제거 하는 계층에 대 한 최소 컴퓨터 수 아래로 내려갈 서비스 발생 하지 것입니다 보장 하 여 계층을 확장할 수 있는지 여부를 확인 합니다. 그런 다음 스크립트에서 실행 되 고 컴퓨터 계층 중 하나를 제거 하 고 가상 컴퓨터 또는 다양 한 실행 중이지 않은 상태에서에서 가상 컴퓨터를 배치 하는 가장 최근에 만든된 가상 컴퓨터를 찾습니다.

#   Description:   The script verifies that you are able to scale in a tier and, if so,
#                  the script locates the most recently created virtual machine running
#                  on the computer tier and either removes the virtual machine or stops,
#                  pauses, stores, or saves the state of the virtual machine.

Param (
   [parameter(Mandatory=$true,ParameterSetName="RemoveVM")]
   [Switch]
   $RemoveVM,

   [parameter(Mandatory=$true,ParameterSetName="RetainVM")]
   [ValidateSet("Stop","Pause","SaveState","Store")]
   [String[]]
   $VMAction,

   [parameter(Mandatory=$true)]
   [String]
   $Service=$(throw "Please provide the name of a service."),

   [parameter(Mandatory=$true)]
   [String]
   $ComputerTier=$(throw "Please provide the name of a computer tier."),

   [parameter(Mandatory=$false,ParameterSetName="RetainVM")]
   [String]
   $LibraryServer,

   [parameter(Mandatory=$false,ParameterSetName="RetainVM")]
   [String]
   $LibraryPath
   )

# Get the service and the computer tier.
$ServiceInstance = Get-SCService -Name $Service
$Tier = Get-SCComputerTier -Service $ServiceInstance | where {$_.Name -eq $ComputerTier}

# Ensure that you are able to scale the tier in. 
If ($Tier.VMs.count -le $Tier.InstanceMinimumCount) {throw "You have reached the instance minimum for this tier."}

# Find the most recently created virtual machine in the tier that is running.
$VMs = @(Get-SCVirtualMachine | where {$_.ComputerTier -eq $Tier -and $_.Status -eq "Running"}) | sort -Property CreationTime -Descending
$VM = $VMs[0]

If ($RemoveVM)
{
   Stop-SCVirtualMachine -VM $VM -Force
   Remove-SCVirtualMachine -VM $VM
}
Else
{
   If ($VMAction -eq "Stop")
   {
      Stop-SCVirtualMachine -VM $VM
   }

   ElseIf ($VMAction -eq "Pause")
   {
      Suspend-SCVirtualMachine -VM $VM
   }

   ElseIf ($VMAction -eq "SaveState")
   {
      Stop-SCVirtualMachine -VM $VM -SaveState
   }

   ElseIf ($VMAction -eq "Store")
   {
      Save-SCVirtualMachine -VM $VM -LibraryServer $LibraryServer -SharePath $LibraryPath
   }

   Else
   {
      throw "You did not provide a valid action for the virtual machine."
   }
}