189 lines
5.9 KiB
PowerShell
189 lines
5.9 KiB
PowerShell
param(
|
|
[string]$OutFile = ".\netgescon-tapi-provider-report.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Get-RegistryValues {
|
|
param([string]$Path)
|
|
|
|
if (-not (Test-Path $Path)) {
|
|
return $null
|
|
}
|
|
|
|
$item = Get-ItemProperty -Path $Path
|
|
$props = @{}
|
|
|
|
foreach ($property in $item.PSObject.Properties) {
|
|
if ($property.Name -in @('PSPath', 'PSParentPath', 'PSChildName', 'PSDrive', 'PSProvider')) {
|
|
continue
|
|
}
|
|
|
|
$props[$property.Name] = $property.Value
|
|
}
|
|
|
|
return $props
|
|
}
|
|
|
|
function Get-RegistryChildren {
|
|
param([string]$Path)
|
|
|
|
if (-not (Test-Path $Path)) {
|
|
return @()
|
|
}
|
|
|
|
return @(Get-ChildItem -Path $Path | ForEach-Object {
|
|
[pscustomobject]@{
|
|
Name = $_.PSChildName
|
|
Path = $_.PSPath
|
|
Values = Get-RegistryValues -Path $_.PSPath
|
|
}
|
|
})
|
|
}
|
|
|
|
function Get-MapValue {
|
|
param(
|
|
[object]$Map,
|
|
[string]$Key
|
|
)
|
|
|
|
if ($null -eq $Map) {
|
|
return $null
|
|
}
|
|
|
|
if ($Map -is [System.Collections.IDictionary] -and $Map.Contains($Key)) {
|
|
return $Map[$Key]
|
|
}
|
|
|
|
return $null
|
|
}
|
|
|
|
function Get-CollectionCount {
|
|
param([object]$Value)
|
|
|
|
if ($null -eq $Value) {
|
|
return 0
|
|
}
|
|
|
|
if ($Value -is [string]) {
|
|
return 1
|
|
}
|
|
|
|
if ($Value -is [System.Collections.ICollection]) {
|
|
return $Value.Count
|
|
}
|
|
|
|
if ($Value -is [System.Array]) {
|
|
return $Value.Length
|
|
}
|
|
|
|
return @($Value).Count
|
|
}
|
|
|
|
Write-Host "[1/6] Leggo stato servizio Telefonia..."
|
|
$tapiService = Get-Service -Name TapiSrv -ErrorAction Stop
|
|
|
|
Write-Host "[2/6] Leggo servizi dipendenti..."
|
|
$dependentServices = @($tapiService.DependentServices | ForEach-Object {
|
|
[pscustomobject]@{
|
|
Name = $_.Name
|
|
DisplayName = $_.DisplayName
|
|
Status = $_.Status.ToString()
|
|
}
|
|
})
|
|
|
|
Write-Host "[3/6] Leggo chiavi registry Telephony..."
|
|
$telephonyRoot = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony'
|
|
$telephonyWowRoot = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Telephony'
|
|
|
|
$telephonyValues = Get-RegistryValues -Path $telephonyRoot
|
|
$telephonyWowValues = Get-RegistryValues -Path $telephonyWowRoot
|
|
$telephonyProviders = Get-RegistryChildren -Path (Join-Path $telephonyRoot 'Providers')
|
|
$telephonyWowProviders = Get-RegistryChildren -Path (Join-Path $telephonyWowRoot 'Providers')
|
|
|
|
Write-Host "[4/6] Cerco riferimenti Panasonic nel registry..."
|
|
$panasonicHits = @()
|
|
foreach ($root in @(
|
|
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony',
|
|
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Telephony',
|
|
'HKLM:\SOFTWARE\Panasonic',
|
|
'HKLM:\SOFTWARE\WOW6432Node\Panasonic'
|
|
)) {
|
|
if (-not (Test-Path $root)) {
|
|
continue
|
|
}
|
|
|
|
$panasonicHits += @(Get-ChildItem -Path $root -Recurse -ErrorAction SilentlyContinue | Where-Object {
|
|
$_.Name -match 'Panasonic|KX|TSP|TAPI'
|
|
} | Select-Object -First 100 | ForEach-Object {
|
|
[pscustomobject]@{
|
|
Path = $_.PSPath
|
|
Name = $_.PSChildName
|
|
Values = Get-RegistryValues -Path $_.PSPath
|
|
}
|
|
})
|
|
}
|
|
|
|
Write-Host "[5/6] Leggo provider COM TAPI registrati..."
|
|
$clsidHits = @()
|
|
foreach ($root in @(
|
|
'HKCR:\CLSID',
|
|
'HKLM:\SOFTWARE\Classes\CLSID'
|
|
)) {
|
|
if (-not (Test-Path $root)) {
|
|
continue
|
|
}
|
|
|
|
$clsidHits += @(Get-ChildItem -Path $root -ErrorAction SilentlyContinue | ForEach-Object {
|
|
$values = Get-RegistryValues -Path $_.PSPath
|
|
$defaultValue = Get-MapValue -Map $values -Key '(default)'
|
|
$localizedString = Get-MapValue -Map $values -Key 'LocalizedString'
|
|
|
|
if ($null -ne $values -and (($defaultValue -as [string]) -match 'Panasonic|TAPI' -or ($localizedString -as [string]) -match 'Panasonic|TAPI')) {
|
|
[pscustomobject]@{
|
|
Path = $_.PSPath
|
|
Name = $_.PSChildName
|
|
Values = $values
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
Write-Host "[6/6] Scrivo report JSON..."
|
|
$report = [pscustomobject]@{
|
|
GeneratedAt = (Get-Date).ToString('o')
|
|
ComputerName = $env:COMPUTERNAME
|
|
UserName = $env:USERNAME
|
|
TapiService = [pscustomobject]@{
|
|
Name = $tapiService.Name
|
|
DisplayName = $tapiService.DisplayName
|
|
Status = $tapiService.Status.ToString()
|
|
StartType = (Get-CimInstance Win32_Service -Filter "Name='TapiSrv'" | Select-Object -ExpandProperty StartMode)
|
|
}
|
|
DependentServices = $dependentServices
|
|
Telephony = [pscustomobject]@{
|
|
RootValues = $telephonyValues
|
|
WowRootValues = $telephonyWowValues
|
|
Providers = $telephonyProviders
|
|
WowProviders = $telephonyWowProviders
|
|
}
|
|
PanasonicRegistryHits = $panasonicHits
|
|
TapiClsidHits = $clsidHits
|
|
}
|
|
|
|
$outDirectory = Split-Path -Path $OutFile -Parent
|
|
if (-not [string]::IsNullOrWhiteSpace($outDirectory) -and -not (Test-Path $outDirectory)) {
|
|
New-Item -ItemType Directory -Path $outDirectory -Force | Out-Null
|
|
}
|
|
|
|
$report | ConvertTo-Json -Depth 8 | Set-Content -Path $OutFile -Encoding UTF8
|
|
|
|
Write-Host ""
|
|
Write-Host ("TapiSrv: {0} ({1})" -f $report.TapiService.Status, $report.TapiService.StartType)
|
|
Write-Host ("Dependent services: {0}" -f (Get-CollectionCount -Value $report.DependentServices))
|
|
Write-Host ("Telephony providers x64: {0}" -f (Get-CollectionCount -Value $report.Telephony.Providers))
|
|
Write-Host ("Telephony providers wow64: {0}" -f (Get-CollectionCount -Value $report.Telephony.WowProviders))
|
|
Write-Host ("Panasonic registry hits: {0}" -f (Get-CollectionCount -Value $report.PanasonicRegistryHits))
|
|
Write-Host ("TAPI CLSID hits: {0}" -f (Get-CollectionCount -Value $report.TapiClsidHits))
|
|
Write-Host ("File creato: {0}" -f $OutFile) |