因此,我必须生成注册表令牌并创建 RDINFRA 代理并更新注册表值并重新启动 RDAgentBootLoader 服务,但更新该值后我无法启动该服务 - 我想知道该服务是否是RDInfraagent 还是我需要单独安装它?
请帮助我找到代码中的错误。
try
{
"Logging in to Azure..."
Connect-AzAccount -Identity
}
catch {
Write-Error -Message $_.Exception
throw $_.Exception
}
# Connect to Azure using your account identity
Connect-AzAccount -Identity
# Set the subscription (if not already set)
Set-AzContext -SubscriptionId "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Define the veriables
$ResourceGroupName = "xxxxxxxxx"
$HostPoolName = "xxxxxxxxxxxxx"
$Hostpool = Get-AzWvdHostPool -Name $HostPoolName -ResourceGroupName $ResourceGroupName -ErrorAction SilentlyContinue
if (!$Hostpool)
{
Write-Host '', "Hostpool '$($HostPoolName)' doesn't exist. It will be created by TF"
} else
{
try
{
# Create token
$RegistrationToken = New-AzWvdRegistrationInfo -ResourceGroupName $ResourceGroupName `
-HostPoolName $HostPoolName `
-ExpirationTime (Get-Date).ToUniversalTime().AddHours(2).ToString('yyyy-MM-ddTHH:mm:ss.fffffffZ')
Write-Host '', "Token created"
Write-Output $RegistrationToken
} catch {
throw $_.exception
}
}
$RegistrationToken | Get-Member
# Define registry path and name
$registryPath = "HKLM:\SOFTWARE\Microsoft\RDInfraAgent"
$registryName = $RegistrationToken
$newRegistryValueData = $RegistrationToken.Token
# Create the registry key if it doesn't exist
if (-not (Test-Path $registryPath)) {
try {
New-Item -Path $registryPath -Force -ErrorAction Stop
Write-Output "Registry key '$registryPath' created successfully."
} catch {
Write-Error "Failed to create registry key '$registryPath': $_"
}
}
# Update registry value
try {
New-ItemProperty -Path $registryPath -Name $registryName -Value $newRegistryValueData -Force -ErrorAction Stop
Write-Output '', "Registry value updated"
} catch {
Write-Error -Message "Failed to update registry value: $_"
}
$serviceName = "RDAgentBootLoader"
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
Write-Output "service:$service"
if ($service) {
Write-Output "RDAgentBootLoader service is installed and $($service.Status)."
} else {
Write-Output "RDAgentBootLoader service is not installed."
}
我想知道我是否已正确安装 RDInfraAgent。我能够生成注册令牌并更新该值,但服务未启动,因为它说服务未安装。
错误:未安装 RDAgentBootLoader 服务。
重新启动服务后,我必须加入此特定主机池中的虚拟机。我在这部分遇到了麻烦,因为我是天蓝色的新手。这是来自门户中的 azure 自动化运行手册
重新启动服务后,我必须加入此特定主机池中的虚拟机。我在这部分遇到了麻烦,因为我是天蓝色的新手。这是来自门户中的 azure 自动化运行手册
将会话主机加入主机池时出现问题
以下是解决 Azure 虚拟桌面代理(RDAgentBootLoader) 问题的故障排除过程。
这是用于解决
RDAgentBootLoader问题的
PowerShell
脚本。
# Define the PowerShell script as a here-string
$script = @"
# Check if the service RDAgentBootLoader is running
$serviceStatus = (Get-Service -Name "RDAgentBootLoader").Status
if ($serviceStatus -eq "Running") {
Write-Output "RDAgentBootLoader service is already running."
} elseif ($serviceStatus -eq "Stopped") {
# Start the service if it's stopped
Start-Service -Name "RDAgentBootLoader"
Write-Output "RDAgentBootLoader service started."
} else {
# Restart the service if it's in any other state (e.g., Paused)
Restart-Service -Name "RDAgentBootLoader"
Write-Output "RDAgentBootLoader service restarted."
}
# Check if the service is now running
$serviceStatus = (Get-Service -Name "RDAgentBootLoader").Status
if ($serviceStatus -ne "Running") {
Write-Output "RDAgentBootLoader service is still not running."
# Define registry path
$registryPath = "HKLM:\SOFTWARE\Microsoft\RDInfraAgent"
# Check if the registry key exists
if (Test-Path $registryPath) {
# Check if IsRegistered is set to 1
$isRegistered = (Get-ItemProperty -Path $registryPath -Name "IsRegistered" -ErrorAction SilentlyContinue).IsRegistered
if ($isRegistered -ne 1) {
# Set IsRegistered to 1 if it's not already set
Set-ItemProperty -Path $registryPath -Name "IsRegistered" -Value 1 -ErrorAction SilentlyContinue
Write-Output "IsRegistered set to 1."
} else {
Write-Output "IsRegistered is already set to 1."
}
# Check if RegistrationToken value exists
$registrationToken = Get-ItemProperty -Path $registryPath -Name "RegistrationToken" -ErrorAction SilentlyContinue
if ($registrationToken) {
# Delete RegistrationToken value if it exists
Remove-ItemProperty -Path $registryPath -Name "RegistrationToken" -ErrorAction SilentlyContinue
Write-Output "RegistrationToken value deleted."
} else {
Write-Output "RegistrationToken value does not exist."
}
# Retrieve BrokerResourceIdURI from the registry
$brokerResourceIdURI = (Get-ItemProperty -Path $registryPath -Name "BrokerResourceIdURI" -ErrorAction SilentlyContinue)."BrokerResourceIdURI"
if ($brokerResourceIdURI -ne $null) {
# Check the health status of the RD Broker URI
$brokerURIHealth = Invoke-WebRequest -Uri "$brokerResourceIdURI/api/health" -UseBasicParsing
if ($brokerURIHealth.StatusCode -eq 200) {
Write-Output "RD Broker URI ($brokerResourceIdURI) is healthy."
} else {
Write-Output "RD Broker URI ($brokerResourceIdURI) is not healthy. Check network connectivity."
}
} else {
Write-Output "BrokerResourceIdURI value does not exist in the registry."
}
} else {
Write-Output "Registry key '$registryPath' does not exist."
}
} else {
Write-Output "RDAgentBootLoader service is running."
}
"@
#The script will run on every AVD session
Connect-AzAccount -Identity
$resourceGroups = Get-AzResourceGroup | Where-Object { ($_.ResourceGroupName -like "Venkat") }
foreach ($rg in $resourceGroups) {
$hostPoolObjects = Get-AzWvdHostPool -ResourceGroupName $rg.ResourceGroupName
foreach ($hostPool in $hostPoolObjects) {
$sessionHosts = Get-AzWvdSessionHost -ResourceGroupName $rg.ResourceGroupName -HostPoolName $hostPool.Name
# Initialize an array to store modified session host names
$modifiedSessionHosts = @()
foreach ($sessionHost in $sessionHosts) {
# Split the session host name by '/' and select the last element
$sessionHostName = ($sessionHost.Name -split '/')[-1]
$modifiedSessionHosts += $sessionHostName
}
# Output the modified session host names
$modifiedSessionHosts
}
}
Foreach($sessionhost in $modifiedSessionHosts){
Invoke-AzVMRunCommand -ResourceGroupName "Venkat" -VMName $modifiedSessionHosts -CommandId 'RunPowerShellScript' -Script $script
}
输出:
注意:在自动化帐户中运行脚本之前,请确保将角色分配给identity。