Public/Get-UnifiDevice.ps1
|
function Get-UnifiDevice { [CmdletBinding()] param( [string]$Site ) if (-not $script:UnifiSession) { Write-Error "Not connected. Run Connect-UnifiController first." return } $siteId = Resolve-UnifiSite $Site $result = Invoke-UnifiRequest -Endpoint '/stat/device' -Site $siteId if (-not $result.data -or $result.data.Count -eq 0) { Write-Warning "No devices found on site '$siteId'." return } $result.data | Select-Object ` @{ N = 'Name'; E = { if ($_.name) { $_.name } else { $_.mac } } }, @{ N = 'Type'; E = { switch ($_.type) { 'uap' { 'Access Point' } 'usw' { 'Switch' } 'ugw' { 'Gateway' } 'udm' { 'Dream Machine'} default { $_.type } } } }, @{ N = 'Model'; E = { $_.model } }, @{ N = 'IP'; E = { $_.ip } }, @{ N = 'MAC'; E = { $_.mac } }, @{ N = 'State'; E = { switch ($_.state) { 0 { 'Disconnected' } 1 { 'Connected' } 2 { 'Pending' } 4 { 'Upgrading' } 5 { 'Provisioning' } default { "State $($_.state)" } } } }, @{ N = 'Version'; E = { $_.version } } } |