Get-WmiObject Win32_Service를 사용하여 실행중인 서비스와 현재 상태를 열거하는 Powershell 스크립트가 있습니다. this one에 기초한 초기 버전으로 Azure 용으로 수정되었습니다. 내 위치 컴퓨터에서 Powershell (하늘색 자동화 부분없이) 스크립트를 실행할 때 제대로 작동하고 관심있는 모든 컴퓨터에 연결할 수 있지만 런북으로 포팅하면 다음과 같은 오류가 발생합니다. "Get-WmiObject : RPC 서버를 사용할 수 없습니다. "Azure Runbook을 사용하는 Azure VM의 모니터링 서비스
Q : 자동화 계정의 사용 권한에 문제가 있습니까? 그렇다면 문제를 해결하기 위해 로컬 컴퓨터에 어떤 계정을 추가해야합니까?
Q : Get-WmiObject가 연결을 시작하는 올바른 방법이 아닙니까? 그렇지 않다면 대신 무엇을 시도해야합니까?
내가 사용하는 코드는 다음과 같습니다 :
[CmdletBinding(SupportsShouldProcess = $true)]
param(
# Servers to check
[Parameter(Mandatory=$true)][string[]]$ServerList,
# Services to check for
[Parameter(Mandatory=$true)][string[]]$includeService
)
# Following modifies the Write-Verbose behavior to turn the messages on globally for this session
$VerbosePreference = "Continue"
$connectionName = "AzureRunAsConnection"
# retry
$retry = 6
$syncOk = $false
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
do
{
try
{
Add-AzureRmAccount -ServicePrincipal -TenantId $servicePrincipalConnection.TenantId -ApplicationId $servicePrincipalConnection.ApplicationId -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
$syncOk = $true
}
catch
{
$ErrorMessage = $_.Exception.Message
$StackTrace = $_.Exception.StackTrace
Write-Warning "Error during sync: $ErrorMessage, stack: $StackTrace. Retry attempts left: $retry"
$retry = $retry - 1
Start-Sleep -s 60
}
} while (-not $syncOk -and $retry -ge 0)
Select-AzureRMSubscription -SubscriptionId $SubscriptionId -TenantId $servicePrincipalConnection.TenantId
$currentSubscription = Get-AzureRMSubscription -SubscriptionId $SubscriptionId -TenantId $servicePrincipalConnection.TenantId
Set-AzureRmContext -SubscriptionId $SubscriptionId;
[email protected]()
[System.Collections.ArrayList]$unreachableServers = @()
Foreach($ServerName in ($ServerList))
{
try
{
$service = Get-WmiObject Win32_Service -ComputerName $servername
}
catch
{}
if ($Service -ne $NULL)
{
foreach ($item in $service)
{
#$item.DisplayName
Foreach($include in $includeService)
{
#write-host $include
if(($item.name).Contains($include) -eq $TRUE)
{
$props += [pscustomobject]@{
servername = $ServerName
name = $item.name
Status = $item.Status
startmode = $item.startmode
state = $item.state
serviceaccount=$item.startname
DisplayName =$item.displayname}
}
}
}
}
else
{
Write-host "Failed to contact server: "$ServerName
$unreachableServers.Add($ServerName)
}
}
$props | Format-Table Servername,Name,startmode,state,serviceaccount,displayname -AutoSize
예, 이것이 결국 제가 해결할 해결책입니다. 요약하면 다음과 같습니다. 1) 사용자 지정 하이브리드 작업자 그룹을 만들었습니다. 2) 해당 그룹에 AD 자격 증명을 연결하여 해당 컴퓨터에 대한 사용 권한을 얻었습니다. 3) "RunAs"매개 변수가있는 하이브리드 작업자 그룹에서 런북을 실행했습니다. – user2766185