다음을 통해 공유


사용자 지정 속성을 사용 하 고 시스템 종료 (스크립트)서비스에서 가상 컴퓨터의 시작 순서를 확인 하려면 컴퓨터 계층

 

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

만들고 있는 개체에 사용자 지정 속성을 추가할 수 System Center 2012 – Virtual Machine Manager(VMM)합니다. 새 사용자 지정 속성을 만들려면 사용은 New-SCCustomProperty cmdlet. 을 만들거나 사용자 지정 속성을 업데이트할 때 사용 하 여에 적용할 수는 속성 개체를 확인할 수 있습니다는 AddMember 매개 변수입니다. 가상 컴퓨터, 가상 컴퓨터 템플릿, 호스트, 호스트 클러스터, 호스트 그룹, 서비스 템플릿, 컴퓨터 계층 및 클라우드 사용자 지정 속성을 적용할 수 있습니다. 하면 사용자 지정 속성을 만들어 개체에 추가 된 후 다음 사용자 지정 속성에 값을 추가 및 사용자 지정 속성 값을 기반으로 개체에 대해 작업을 수행할 수 있습니다.

부인

다음 스크립트는 컴퓨터 계층 개체에 대 한 사용자 지정 속성을 만듭니다. 다음 계층에서 가상 컴퓨터의 시작 및 종료 순서를 결정 하는 사용자 지정 속성에 값을 적용 합니다.

<#
  Description:   This script creates a custom property for computer tier objects.
                 The script then applies values to the custom properties on the
                 computer tiers. Based on property values, the script stops the 
                 virtual machines in the specified order, and then starts the 
                 virtual machines, also in the specified order.
#>

# Create custom properties for the computer tiers.
$CustomProp = New-SCCustomProperty -Name StopStartOrder -AddMember "ComputerTier"

# Get the computer tiers on which you want to set the shutdown and startup order.
$Service = Get-SCService -Name "NewService6"
$Tiers = Get-SCComputerTier -Service $Service
$TierNumber = $Tiers.count

# Set the shutdown/startup order custom property on the computer tiers.
$ComputerTier1 = Get-SCComputerTier -Service $Service | where {$_.Name -eq "Web Tier"}
Set-SCCustompropertyValue -CustomProperty $CustomProp -InputObject $ComputerTier1 -Value "1"
$ComputerTier2 = Get-SCComputerTier -Service $Service | where {$_.Name -eq "ComputerTier2"}
Set-SCCustompropertyValue -CustomProperty $CustomProp -InputObject $ComputerTier2 -Value "2"

# Stop the virtual machines in order before stopping the service.
$i = 1
While ($i -le $TierNumber)
{
   Get-SCComputerTier -Service $Service | where {$_.CustomProperty.Values -eq "$i"} | Get-SCVirtualMachine | Stop-SCVirtualMachine -Shutdown

   $i = $i+1
}

# Stop the service.
Stop-SCService -Service $Service

# Pause to ensure that the service is stopped.
Start-Sleep "30"

# Start the virtual machines in order before starting the service.
$i = 1
While ($i -le $TierNumber)
{
   Get-SCComputerTier -Service $Service | where {$_.CustomProperty.Values -eq "$i"} | Get-SCVirtualMachine | Start-SCVirtualMachine

   $i = $i+1
}

# Start the service.
Start-SCService -Service $Service