Initial commit. Working and linked on PSGallery
This commit is contained in:
31
Public/Get-UnifiClient.ps1
Normal file
31
Public/Get-UnifiClient.ps1
Normal file
@@ -0,0 +1,31 @@
|
||||
function Get-UnifiClient {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Site,
|
||||
|
||||
# Limit to currently connected clients only (default returns all known clients)
|
||||
[switch]$Active
|
||||
)
|
||||
|
||||
if (-not $script:UnifiSession) {
|
||||
Write-Error "Not connected. Run Connect-UnifiController first."
|
||||
return
|
||||
}
|
||||
|
||||
$siteId = Resolve-UnifiSite $Site
|
||||
$endpoint = if ($Active) { '/stat/sta' } else { '/stat/alluser' }
|
||||
$result = Invoke-UnifiRequest -Endpoint $endpoint -Site $siteId
|
||||
|
||||
if (-not $result.data -or $result.data.Count -eq 0) {
|
||||
Write-Warning "No clients found on site '$siteId'."
|
||||
return
|
||||
}
|
||||
|
||||
$result.data | Select-Object `
|
||||
@{ N = 'Hostname'; E = { if ($_.hostname) { $_.hostname } elseif ($_.name) { $_.name } else { '-' } } },
|
||||
@{ N = 'IP'; E = { if ($_.ip) { $_.ip } elseif ($_.fixed_ip) { "$($_.fixed_ip)*" } else { '-' } } },
|
||||
@{ N = 'MAC'; E = { $_.mac } },
|
||||
@{ N = 'Network'; E = { if ($_.essid) { $_.essid } elseif ($_.network) { $_.network } else { '-' } } },
|
||||
@{ N = 'Type'; E = { if ($_.is_wired) { 'Wired' } else { 'Wireless' } } },
|
||||
@{ N = 'Signal'; E = { if (-not $_.is_wired -and $_.rssi) { "$($_.signal) dBm (RSSI $($_.rssi))" } else { '-' } } }
|
||||
}
|
||||
Reference in New Issue
Block a user