Forum Discussion
Teams Rooms - Reinstall Win Device Admin Agent Service
I have rerun the device reset process. This time it has installed the service and the device is reporting in the TAC. Will see if it continues to do so.
Here is a script to fix the agent
$AARegistryPath = "HKLM:\SOFTWARE\Microsoft\PPI\SkypeSettings\INSTALL_AA"
$registryKey = "EnableAAInstall"
$SRSUser = "Skype"
$SRSPackage = "Microsoft.SkypeRoomSystem"
$AgentBinaryName = "WinAgentSvc.exe"
$ServiceName = "WinDeviceAdminAgent"
$ServiceDisplayName = "Win Device Admin Agent"
$ServiceDescription = "Teams Admin Agent for Microsoft Teams Room"
function Join-Paths2 {
$path = $args[0]
$args[1..$args.Count] | ForEach-Object { $path = Join-Path $path $_ }
$path
}
function Get-IsAdminAgentInstallationEnabled {
$IsEnableAAInstallSet = $true;
if (Test-Path -Path $AARegistryPath) {
$registry = Get-Item -path $AARegistryPath -ErrorAction SilentlyContinue
if ($null -ne $registry) {
try {
$IsEnableAAInstallSet = ([bool]::Parse($registry.GetValue($registryKey, $true)))
}
catch {
}
}
}
return $IsEnableAAInstallSet
}
function Get-SRSInstallPath {
$installPath = ""
$user = $SRSUser
$packageName = $SRSPackage
$package = Get-AppxPackage -User $user -Name $packageName
if ($null -ne $package) {
$installPath = $package.InstallLocation
}
return $installPath
}
function Get-AdminAgentVersionInFolder {
param(
[parameter(Mandatory = $true)]
[string]$FolderPath
)
$version = $null
$serviceFilePath = Join-Path $FolderPath $AgentBinaryName
if (Test-Path -Path $serviceFilePath) {
try {
$version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($serviceFilePath).FileVersion
}
catch {
Write-Error -Message "Cannot find admin agent version in path $FolderPath" -Exception $_.Exception
}
}
return $version
}
function CreateServiceUsingServiceController {
param(
[parameter(Mandatory = $true)]
[string]$ServiceFilePath
)
$processArgs = "create $ServiceName binPath=""\""$ServiceFilePath\"""" start=auto DisplayName=""$ServiceDisplayName"""
$process = [System.Diagnostics.Process]::Start("sc.exe", $processArgs)
$process.WaitForExit();
}
$DefaultAgentInstallPath = Join-Paths2 ${env:SystemDrive} "Program Files" "AdminAgent"
# Must be running as admin
$isElevated = "non-elevated"
if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
$isElevated = "elevated"
}
if ($isElevated -ne "elevated") {
Write-Output "This script must be run with administrative privileges. Use an elevated command prompt."
exit 1
}
$IsAgentInstallationEnabled = Get-IsAdminAgentInstallationEnabled
if ($IsAgentInstallationEnabled -eq $false) {
Write-Output "Admin Agent installation is disabled in the registry."
Write-Output "Removing registry key: $AARegistryPath"
Remove-Item -Path $AARegistryPath -Recurse
Write-Output "Admin Agent installation is now enabled."
}
Write-Output "Checking if service ""$ServiceDisplayName"" is already installed and running ..."
# If agent is installed, service must be in stopped state
$AgentService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($null -ne $AgentService -and $AgentService.Status -ne [System.ServiceProcess.ServiceControllerStatus]::Stopped) {
Write-Output "The service ""$AgentService.DisplayName"" must be stopped for repair."
Write-Output "Please stop the service using the Powershell command:"
Write-Output "Stop-Service -Name ""$ServiceName"""
exit 1
}
Write-Output "Service ""$ServiceDisplayName"" is not present"
Write-Output "Checking for package $SRSPackage ..."
$SRSInstallPath = Get-SRSInstallPath
# Check if the agent source path is available and valid
if (($null -eq $SRSInstallPath) -or ($SRSInstallPath.Length -eq 0)) {
Write-Output "Skype Room System is not installed. This app must be installed for this script to proceed. Please install this app and run this script again if the issue persists."
exit 1
}
if (-not (Test-Path -Path $SRSInstallPath)) {
Write-Output "The path ""$SRSInstallPath"" is not valid. This path must exist."
exit 1
}
Write-Output "The package ""$SRSPackage"" is present."
$AgentSourceDirectory = Join-Path $SRSInstallPath "Scripts\\AdminAgent"
if (-not (Test-Path -Path $AgentSourceDirectory)) {
Write-Output "Unable to find the path ""$AgentSourceDirectory"". Cannot proceed with the repair."
exit 1
}
# Check if we have a valid version of admin agent in the source folder
$AgentSourceVersion = Get-AdminAgentVersionInFolder -FolderPath $AgentSourceDirectory
if ($null -eq $AgentSourceVersion) {
Write-Output "Cannot find version information of admin agent in source folder. Cannot proceed with the repair."
exit 1
}
Write-Output "Found Admin Agent version $AgentSourceVersion bundled in the package."
$AgentInstallPath = $DefaultAgentInstallPath
Write-Output "Checking for existing installations at ""$AgentInstallPath""."
# Remove older installations
if (Test-Path -Path $AgentInstallPath) {
Write-Output "Removing existing installation at ""$AgentInstallPath""..."
Remove-Item "$AgentInstallPath\\*.*" -Recurse
Start-Sleep -Seconds 2
Remove-Item $AgentInstallPath -Recurse
Start-Sleep -Seconds 2
}
# Copy admin agent binaries
if (-not (Test-Path -Path $AgentInstallPath)) {
Write-Output "Creating folder ""$AgentInstallPath""."
New-Item -Path $AgentInstallPath -ItemType Directory
}
Write-Output "Copying files for Admin Agent..."
Copy-Item -Path $AgentSourceDirectory\* -Destination $AgentInstallPath -Recurse
Write-Output "Admin Agent files copied."
$AgentService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
# Delete existing service registration if present
if ($null -ne $AgentService) {
Write-Output "Removing existing service registration for $ServiceDisplayName"
sc.exe delete $ServiceName
}
$AgentService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
# Create a new service if required
if ($null -eq $AgentService) {
Write-Output "Registering service $ServiceDisplayName"
$serviceFilePath = Join-Path $AgentInstallPath $AgentBinaryName
CreateServiceUsingServiceController -ServiceFilePath $serviceFilePath
sc.exe failure $ServiceName reset=600 actions=restart/60000/restart/120000/restart/240000
}
else {
Write-Output "W: Service registration not removed"
}
Write-Output "Starting service ""$ServiceName"""
# Start the service
sc.exe start $ServiceName
Write-Output "Repair is complete"
- NThomanMay 18, 2023Iron ContributorThanks... did the trick for one of the systems we rebuilt.
- Michel_C2803Feb 17, 2023Copper Contributor
fabiogross Script Works like a Charm.. Many Thanks!!!