140 lines
4.3 KiB
PowerShell
140 lines
4.3 KiB
PowerShell
param(
|
|
[string]$Filter = "",
|
|
[string]$OutFile = ".\netgescon-tapi-info.json",
|
|
[switch]$IncludeMembers,
|
|
[switch]$ShowRawMembers
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Get-SafeComValue {
|
|
param(
|
|
[Parameter(Mandatory = $true)] $Object,
|
|
[Parameter(Mandatory = $true)] [string]$Name
|
|
)
|
|
|
|
try {
|
|
return $Object.$Name
|
|
}
|
|
catch {
|
|
return $null
|
|
}
|
|
}
|
|
|
|
function Convert-ComCollectionToArray {
|
|
param([Parameter(Mandatory = $true)] $Collection)
|
|
|
|
$items = @()
|
|
try {
|
|
foreach ($item in $Collection) {
|
|
$items += $item
|
|
}
|
|
}
|
|
catch {
|
|
}
|
|
|
|
return ,$items
|
|
}
|
|
|
|
function Get-AddressSnapshot {
|
|
param(
|
|
[Parameter(Mandatory = $true)] $Address,
|
|
[string]$FilterValue = ""
|
|
)
|
|
|
|
$addressName = [string](Get-SafeComValue -Object $Address -Name "AddressName")
|
|
$serviceProviderName = [string](Get-SafeComValue -Object $Address -Name "ServiceProviderName")
|
|
$dialableAddress = [string](Get-SafeComValue -Object $Address -Name "DialableAddress")
|
|
$state = Get-SafeComValue -Object $Address -Name "State"
|
|
$mediaTypes = Get-SafeComValue -Object $Address -Name "MediaTypes"
|
|
$bearerMode = Get-SafeComValue -Object $Address -Name "BearerMode"
|
|
|
|
$terminals = @()
|
|
$terminalCollection = Get-SafeComValue -Object $Address -Name "Terminals"
|
|
if ($null -ne $terminalCollection) {
|
|
foreach ($terminal in (Convert-ComCollectionToArray -Collection $terminalCollection)) {
|
|
$terminals += [pscustomobject]@{
|
|
Name = [string](Get-SafeComValue -Object $terminal -Name "Name")
|
|
Direction = Get-SafeComValue -Object $terminal -Name "Direction"
|
|
TerminalCls = [string]$terminal.GetType().FullName
|
|
}
|
|
}
|
|
}
|
|
|
|
$match = $true
|
|
if ($FilterValue -ne "") {
|
|
$haystack = @($addressName, $serviceProviderName, $dialableAddress) -join " | "
|
|
$match = $haystack -match [regex]::Escape($FilterValue)
|
|
}
|
|
|
|
return [pscustomobject]@{
|
|
AddressName = $addressName
|
|
ServiceProviderName = $serviceProviderName
|
|
DialableAddress = $dialableAddress
|
|
State = $state
|
|
MediaTypes = $mediaTypes
|
|
BearerMode = $bearerMode
|
|
TerminalCount = $terminals.Count
|
|
Terminals = $terminals
|
|
MatchesFilter = $match
|
|
}
|
|
}
|
|
|
|
Write-Host "[1/5] Creo l'oggetto COM TAPI..."
|
|
$tapi = New-Object -ComObject TAPI.TAPI
|
|
|
|
Write-Host "[2/5] Inizializzo TAPI..."
|
|
$tapi.Initialize()
|
|
|
|
Write-Host "[3/5] Leggo le informazioni generali..."
|
|
$addressesRaw = @(Convert-ComCollectionToArray -Collection $tapi.Addresses)
|
|
$addressSnapshots = @()
|
|
foreach ($address in $addressesRaw) {
|
|
$addressSnapshots += Get-AddressSnapshot -Address $address -FilterValue $Filter
|
|
}
|
|
|
|
if ($Filter -ne "") {
|
|
$addressSnapshots = @($addressSnapshots | Where-Object { $_.MatchesFilter })
|
|
}
|
|
|
|
$memberDump = @()
|
|
if ($IncludeMembers) {
|
|
$memberDump = @(
|
|
$tapi | Get-Member | Sort-Object MemberType, Name | Select-Object Name, MemberType, Definition
|
|
)
|
|
}
|
|
|
|
$rawAddressMembers = @()
|
|
if ($ShowRawMembers -and $addressesRaw.Count -gt 0) {
|
|
$rawAddressMembers = @(
|
|
$addressesRaw[0] | Get-Member | Sort-Object MemberType, Name | Select-Object Name, MemberType, Definition
|
|
)
|
|
}
|
|
|
|
$report = [pscustomobject]@{
|
|
GeneratedAt = (Get-Date).ToString("o")
|
|
ComputerName = $env:COMPUTERNAME
|
|
UserName = $env:USERNAME
|
|
Filter = $Filter
|
|
AddressCount = $addressSnapshots.Count
|
|
Addresses = $addressSnapshots
|
|
TapiMembers = $memberDump
|
|
FirstAddressDump = $rawAddressMembers
|
|
}
|
|
|
|
Write-Host "[4/5] Scrivo il report JSON in $OutFile"
|
|
$report | ConvertTo-Json -Depth 8 | Set-Content -Path $OutFile -Encoding UTF8
|
|
|
|
Write-Host "[5/5] Riepilogo rapido"
|
|
Write-Host "Macchina: $($report.ComputerName)"
|
|
Write-Host "Utente: $($report.UserName)"
|
|
Write-Host "Indirizzi TAPI trovati: $($report.AddressCount)"
|
|
foreach ($address in $addressSnapshots) {
|
|
Write-Host (" - {0} | Provider: {1} | Dialable: {2} | State: {3}" -f $address.AddressName, $address.ServiceProviderName, $address.DialableAddress, $address.State)
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "File creato: $OutFile"
|
|
Write-Host "Mandami il contenuto del JSON o almeno le righe del riepilogo rapido."
|