param( [Parameter(Mandatory = $true)] [string]$Extension, [string]$OutFile = ".\netgescon-tapi-address-inspect.json" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" function Get-SafeProperty { param( [Parameter(Mandatory = $true)] $Object, [Parameter(Mandatory = $true)] [string]$Name ) try { return $Object.$Name } catch { return $null } } function Get-SafeMethodResult { param( [Parameter(Mandatory = $true)] $Object, [Parameter(Mandatory = $true)] [string]$MethodName, [object[]]$Arguments = @() ) try { return $Object.GetType().InvokeMember($MethodName, [System.Reflection.BindingFlags]::InvokeMethod, $null, $Object, $Arguments) } catch { return $null } } function Convert-ComCollectionToArray { param($Collection) $items = @() if ($null -eq $Collection) { return $items } try { foreach ($item in $Collection) { $items += $item } } catch { } return ,$items } $tapi = New-Object -ComObject TAPI.TAPI $tapi.Initialize() $addresses = @(Convert-ComCollectionToArray -Collection $tapi.Addresses) $target = $addresses | Where-Object { ($_.DialableAddress -as [string]) -eq $Extension -or ($_.AddressName -as [string]) -match [regex]::Escape($Extension) } | Select-Object -First 1 if (-not $target) { throw "Nessun indirizzo TAPI trovato per extension=$Extension" } $callsProperty = Get-SafeProperty -Object $target -Name 'Calls' $calls = @(Convert-ComCollectionToArray -Collection $callsProperty) $enumCalls = Get-SafeMethodResult -Object $target -MethodName 'EnumerateCalls' $report = [pscustomobject]@{ GeneratedAt = (Get-Date).ToString('o') Extension = $Extension Address = [pscustomobject]@{ AddressName = [string](Get-SafeProperty -Object $target -Name 'AddressName') DialableAddress = [string](Get-SafeProperty -Object $target -Name 'DialableAddress') ServiceProviderName = [string](Get-SafeProperty -Object $target -Name 'ServiceProviderName') State = Get-SafeProperty -Object $target -Name 'State' MediaTypes = Get-SafeProperty -Object $target -Name 'MediaTypes' BearerMode = Get-SafeProperty -Object $target -Name 'BearerMode' } AddressMembers = @($target | Get-Member | Sort-Object MemberType, Name | Select-Object Name, MemberType, Definition) CallsPropertyCount = $calls.Count CallsPropertySnapshot = @($calls | ForEach-Object { [pscustomobject]@{ TypeName = $_.GetType().FullName State = Get-SafeProperty -Object $_ -Name 'State' CallState = Get-SafeProperty -Object $_ -Name 'CallState' } }) EnumerateCallsType = if ($null -eq $enumCalls) { $null } else { $enumCalls.GetType().FullName } } $report | ConvertTo-Json -Depth 8 | Set-Content -Path $OutFile -Encoding UTF8 Write-Host "AddressName: $($report.Address.AddressName)" Write-Host "DialableAddress: $($report.Address.DialableAddress)" Write-Host "ServiceProvider: $($report.Address.ServiceProviderName)" Write-Host "State: $($report.Address.State)" Write-Host "CallsPropertyCount: $($report.CallsPropertyCount)" Write-Host "File creato: $OutFile"