PwshUnifi.psm1
#Region './Private/Get-PrivateFunction.ps1' -1 function Get-PrivateFunction { <# .SYNOPSIS This is a sample Private function only visible within the module. .DESCRIPTION This sample function is not exported to the module and only return the data passed as parameter. .EXAMPLE $null = Get-PrivateFunction -PrivateData 'NOTHING TO SEE HERE' .PARAMETER PrivateData The PrivateData parameter is what will be returned without transformation. #> [cmdletBinding()] [OutputType([string])] param ( [Parameter()] [String] $PrivateData ) process { Write-Output $PrivateData } } #EndRegion './Private/Get-PrivateFunction.ps1' 32 #Region './Public/Add-UnifiSite.ps1' -1 function Add-UnifiSite { <# .SYNOPSIS Add a new site to UniFi .DESCRIPTION Add a new site to UniFi .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName It can be any existing site name. Default is the 'default' name .PARAMETER SiteDesc New site target description. Usually the customer's domain short name. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Add-UnifiSite -Url $Url -WebSession $session -SiteName 'default' -SiteDesc 'MyNewSite' #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName = 'default', [Parameter(Mandatory=$true)] [string]$SiteDesc ) begin { [hashtable]$Body = @{ "cmd" = "add-site" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/sitemgr" if($PSBoundParameters.containskey("SiteDesc")) { $Body["desc"] = $SiteDesc } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Add-UnifiSite.ps1' 68 #Region './Public/Approve-UnifiGuestAccess.ps1' -1 function Approve-UnifiGuestAccess { <# .SYNOPSIS Authorizes a guest to access the network. .DESCRIPTION Authorizes a guest to access the network. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Approve-UnifiGuestAccess -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "authorize-guest" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/stamgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Approve-UnifiGuestAccess.ps1' 70 #Region './Public/Backup-Unifi.ps1' -1 function Backup-Unifi { <# .SYNOPSIS Created a new backup at a fixed location on the host .DESCRIPTION Created a new backup at a fixed location on the host .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site name. Default 'default' .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Backup-Unifi -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName = 'default' ) begin { [hashtable]$Body = @{ "cmd" = "backup" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/backup" try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Backup-Unifi.ps1' 62 #Region './Public/Block-UnifiClient.ps1' -1 function Block-UnifiClient { <# .SYNOPSIS Blocks a client from accessing the network .DESCRIPTION Blocks a client from accessing the network .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Block-UnifiClient -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "block-sta" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/stamgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Block-UnifiClient.ps1' 71 #Region './Public/Block-UnifiGuestAccess.ps1' -1 function Block-UnifiGuestAccess { <# .SYNOPSIS Prevents a guest from accessing the network. .DESCRIPTION Prevents a guest from accessing the network. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Block-UnifiGuestAccess -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "unauthorize-guest" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/stamgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Block-UnifiGuestAccess.ps1' 70 #Region './Public/Disconnect-UnifiClient.ps1' -1 function Disconnect-UnifiClient { <# .SYNOPSIS Blocks a client from accessing the network .DESCRIPTION Blocks a client from accessing the network .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Disconnect-UnifiClient -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "block-sta" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/stamgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Disconnect-UnifiClient.ps1' 71 #Region './Public/Find-UnifiDevice.ps1' -1 function Find-UnifiDevice { <# .SYNOPSIS Blink the device to help locating it. .DESCRIPTION Blink the device to help locating it. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device's mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Find-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "set-locate" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Find-UnifiDevice.ps1' 68 #Region './Public/Get-UnifiActiveClient.ps1' -1 function Get-UnifiActiveClient { <# .SYNOPSIS List connected clients for target Site .DESCRIPTION List connected clients for target Site .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiActiveClient -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/sta" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiActiveClient.ps1' 57 #Region './Public/Get-UnifiAdministrator.ps1' -1 function Get-UnifiAdministrator { <# .SYNOPSIS List administrator permissions for all sites .DESCRIPTION List administrator permissions for all sites .PARAMETER Url UniFi URL .PARAMETER WebSession Target WebSession .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiAdministrator -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession ) begin { $Api = "$($Url)/api/stat/admin" } process { try { $sites = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $sites.data } end { return $Output } } #EndRegion './Public/Get-UnifiAdministrator.ps1' 49 #Region './Public/Get-UnifiBackup.ps1' -1 function Get-UnifiBackup { <# .SYNOPSIS List of backup files .DESCRIPTION List of backup files .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site name. Default 'default' .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiBackup -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName = 'default' ) begin { [hashtable]$Body = @{ "cmd" = "list-backups" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/backup" try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiBackup.ps1' 62 #Region './Public/Get-UnifiClientHistory.ps1' -1 function Get-UnifiClientHistory { <# .SYNOPSIS Gets all clients known to UniFi. This contains both clients currently connected as well as clients that were connected in the past. .DESCRIPTION Gets all clients known to UniFi. This contains both clients currently connected as well as clients that were connected in the past. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiClientHistory -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/alluser" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiClientHistory.ps1' 57 #Region './Public/Get-UnifiClientHistoryByMacAddress.ps1' -1 function Get-UnifiClientHistoryByMacAddress { <# .SYNOPSIS Gets the connection history of the client with the provided MAC Address. .DESCRIPTION Gets the connection history of the client with the provided MAC Address. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .PARAMETER Limit Amount of historic items to retrieve. Default 5 .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Get-UnifiClientHistoryByMacAddress -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress, [Parameter(Mandatory=$false)] [int]$Limit = 5 ) begin { [hashtable]$Body = @{ "_limit" = $Limit "_sort" = "-assoc_time" } } process { $Api = "$($Url)/api/s/$($SiteName)/stat/device" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiClientHistoryByMacAddress.ps1' 76 #Region './Public/Get-UnifiDevice.ps1' -1 function Get-UnifiDevice { <# .SYNOPSIS Gets a list of all UniFi devices. .DESCRIPTION Gets a list of all UniFi devices. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/device" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiDevice.ps1' 57 #Region './Public/Get-UnifiLoggedInUser.ps1' -1 function Get-UnifiLoggedInUser { <# .SYNOPSIS Get logged in user .DESCRIPTION Get logged in user .PARAMETER Url UniFi URL .PARAMETER WebSession Target WebSession .PARAMETER IsUdmPro Switch parameter. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiLoggedInUser -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$false)] [switch]$IsUdmPro ) begin { $Api = "$($Url)/api/self" if($PSBoundParameters.containskey("IsUdmPro")) { $Api = "$($Url)/api/users/self" } } process { try { $sites = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $sites.data } end { return $Output } } #EndRegion './Public/Get-UnifiLoggedInUser.ps1' 58 #Region './Public/Get-UnifiSession.ps1' -1 function Get-UnifiSession { <# .SYNOPSIS Create a new session with the Unifi API .DESCRIPTION Create a new session with the Unifi API .PARAMETER Url Target URL to the UNIFI controller .PARAMETER Credential PSCredential for the UNIFI controller .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>Get-UnifiSession -Url $Url -Credential $Credential #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [pscredential]$Credential ) begin { $Api = "$($Url)/api/login" $Body = @{ username = $Credential.UserName password = $Credential.GetNetworkCredential().Password } } process { try { $result = Invoke-WebRequest -Uri $Api -Method Post -ContentType 'application/json' -SessionVariable UnifiSession -Body $($Body|ConvertTo-Json -Depth 99) -SkipCertificateCheck -ErrorAction Stop if($result.StatusCode -ne 200) { throw $result } } catch { throw $_.Exception.Message } } end { return $UnifiSession } } #EndRegion './Public/Get-UnifiSession.ps1' 55 #Region './Public/Get-UnifiSite.ps1' -1 function Get-UnifiSite { <# .SYNOPSIS List all Sites registered with UniFi .DESCRIPTION List all Sites registered with UniFi .PARAMETER Url UniFi URL .PARAMETER WebSession Target WebSession .PARAMETER SiteDesc Target SiteDesc. Returns all when not specified .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session -SiteDesc 'MySite' PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$false)] [string]$SiteDesc ) begin { $Api = "$($Url)/api/self/sites" } process { try { $sites = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $sites.data if($PSBoundParameters.ContainsKey("SiteDesc")) { $Output = $Sites.data | Where-Object {$_.desc -ilike "*$($SiteDesc)*"} } } end { return $Output } } #EndRegion './Public/Get-UnifiSite.ps1' 57 #Region './Public/Get-UnifiSiteActiveRoute.ps1' -1 function Get-UnifiSiteActiveRoute { <# .SYNOPSIS All active routes .DESCRIPTION All active routes .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteActiveRoute -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteActiveRoute -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/routing" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteActiveRoute.ps1' 63 #Region './Public/Get-UnifiSiteAdmin.ps1' -1 function Get-UnifiSiteAdmin { <# .SYNOPSIS List all admins and permissions for the target site. .DESCRIPTION List all admins and permissions for the target site. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site name. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSiteAdmin -Url $Url -WebSession $session -SiteName 'default' -SiteDesc 'MyNewSite' PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { [hashtable]$Body = @{ "cmd" = "get-admins" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/sitemgr" try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteAdmin.ps1' 62 #Region './Public/Get-UnifiSiteCountryCode.ps1' -1 function Get-UnifiSiteCountryCode { <# .SYNOPSIS Returns list of country codes associated with the site. .DESCRIPTION Returns list of country codes associated with the site. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteCountryCode -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteCountryCode -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/ccode" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteCountryCode.ps1' 63 #Region './Public/Get-UnifiSiteDpi.ps1' -1 function Get-UnifiSiteDpi { <# .SYNOPSIS Return DPI status .DESCRIPTION Return DPI status .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER Type The type of choice .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteDpi -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteDpi -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [ValidateSet("by_app","by_cat")] [string]$Type ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/sitedpi?type="+"$($Type)" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteDpi.ps1' 69 #Region './Public/Get-UnifiSiteDynamicDnsInfo.ps1' -1 function Get-UnifiSiteDynamicDnsInfo { <# .SYNOPSIS Return Dynamic DNS information .DESCRIPTION Return Dynamic DNS information .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteDynamicDnsInfo -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteDynamicDnsInfo -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/dynamicdnsInfo" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteDynamicDnsInfo.ps1' 63 #Region './Public/Get-UnifiSiteEvent.ps1' -1 function Get-UnifiSiteEvent { <# .SYNOPSIS List site events by most recents. First 3000. .DESCRIPTION List site events by most recents. First 3000. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteEvent -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteEvent -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/event" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteEvent.ps1' 63 #Region './Public/Get-UnifiSiteFirewallGroup.ps1' -1 function Get-UnifiSiteFirewallGroup { <# .SYNOPSIS User defined firewall groups .DESCRIPTION User defined firewall groups .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteFirewallGroup -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/rest/firewallgroup" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteFirewallGroup.ps1' 56 #Region './Public/Get-UnifiSiteFirewallRule.ps1' -1 function Get-UnifiSiteFirewallRule { <# .SYNOPSIS User defined firewall rules. It will not return auto generated rules. .DESCRIPTION User defined firewall rules. It will not return auto generated rules. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteFirewallRule -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteFirewallRule -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/rest/firewallrule" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteFirewallRule.ps1' 63 #Region './Public/Get-UnifiSiteHealth.ps1' -1 function Get-UnifiSiteHealth { <# .SYNOPSIS Returns the health status of the site .DESCRIPTION Returns the health status of the site .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteHealth -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/health" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteHealth.ps1' 56 #Region './Public/Get-UnifiSitePortForwarding.ps1' -1 function Get-UnifiSitePortForwarding { <# .SYNOPSIS List all port forward configured on the site. .DESCRIPTION List all port forward configured on the site. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSitePortForwarding -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSitePortForwarding -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/rest/portforward" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSitePortForwarding.ps1' 63 #Region './Public/Get-UnifiSiteRadiusAccount.ps1' -1 function Get-UnifiSiteRadiusAccount { <# .SYNOPSIS Get Radius Account .DESCRIPTION Get Radius Account .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteRadiusAccount -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteRadiusAccount -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/rest/account" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteRadiusAccount.ps1' 63 #Region './Public/Get-UnifiSiteRadiusProfile.ps1' -1 function Get-UnifiSiteRadiusProfile { <# .SYNOPSIS Get Radius Profile .DESCRIPTION Get Radius Profile .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteRadiusProfile -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteRadiusProfile -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/rest/radiusprofile" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteRadiusProfile.ps1' 63 #Region './Public/Get-UnifiSiteRfCode.ps1' -1 function Get-UnifiSiteRfCode { <# .SYNOPSIS List all RF channels based on the site country code .DESCRIPTION List all RF channels based on the site country code .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteRfCode -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteRfCode -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/current-channel" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteRfCode.ps1' 63 #Region './Public/Get-UnifiSiteRogueAccessPoint.ps1' -1 function Get-UnifiSiteRogueAccessPoint { <# .SYNOPSIS Get Rogue access points .DESCRIPTION Get Rogue access points .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteRogueAccessPoint -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteRogueAccessPoint -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/rogueap" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteRogueAccessPoint.ps1' 63 #Region './Public/Get-UnifiSiteSetting.ps1' -1 function Get-UnifiSiteSetting { <# .SYNOPSIS Detailed site settings .DESCRIPTION Detailed site settings .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteSetting -Url $Url -WebSession $session -SiteName $MySite.name .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteSetting -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/rest/setting" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteSetting.ps1' 62 #Region './Public/Get-UnifiSiteSpeedTestStatus.ps1' -1 function Get-UnifiSiteSpeedTestStatus { <# .SYNOPSIS Get status of the current speed test .DESCRIPTION Get status of the current speed test .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Get-UnifiSiteSpeedTestStatus -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { [hashtable]$Body = @{ "cmd" = "speedtest-status" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteSpeedTestStatus.ps1' 59 #Region './Public/Get-UnifiSiteStat.ps1' -1 function Get-UnifiSiteStat { <# .SYNOPSIS List all Sites registered with UniFi with an additional information on health and new alerts for each site .DESCRIPTION List all Sites registered with UniFi with an additional information on health and new alerts for each site .PARAMETER Url UniFi URL .PARAMETER WebSession Target WebSession .PARAMETER SiteName Target sitename. Returns all when not specified .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSiteStat -Url $Url -WebSession $session -SiteName 'MySite' PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$false)] [string]$SiteName ) begin { $Api = "$($Url)/api/stat/sites" } process { try { $sites = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $sites.data if($PSBoundParameters.ContainsKey("SiteName")) { $Output = $Sites.data | Where-Object {$_.desc-ieq $SiteName} } } end { return $Output } } #EndRegion './Public/Get-UnifiSiteStat.ps1' 57 #Region './Public/Get-UnifiSiteSysinfo.ps1' -1 function Get-UnifiSiteSysinfo { <# .SYNOPSIS High level information about the controller .DESCRIPTION High level information about the controller .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiSiteSysinfo -Url $Url -WebSession $session -SiteName $MySite.name .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiSiteSysinfo -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/stat/sysinfo" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiSiteSysinfo.ps1' 62 #Region './Public/Get-UnifiStatus.ps1' -1 function Get-UnifiStatus { <# .SYNOPSIS Returns some very basic server information .DESCRIPTION Returns some very basic server information .PARAMETER Url UniFi URL .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>Get-UnifiStatus -Url $Url #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url ) begin { $Api = "$($Url)/status" } process { try { $data = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } } end { return $data.meta } } #EndRegion './Public/Get-UnifiStatus.ps1' 43 #Region './Public/Get-UnifiStiteSwitchPortProfile.ps1' -1 function Get-UnifiStiteSwitchPortProfile { <# .SYNOPSIS Return Switch port profiles .DESCRIPTION Return Switch port profiles .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiStiteSwitchPortProfile -Url $Url -WebSession $session -SiteName $MySite.name .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Get-UnifiSite -Url $Url -WebSession $session | Get-UnifiStiteSwitchPortProfile -Url $Url -WebSession $session PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { } process { $Api = "$($Url)/api/s/$($SiteName)/rest/portconf" try { $devices = Invoke-RestMethod -Uri $Api -Method Get -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiStiteSwitchPortProfile.ps1' 62 #Region './Public/Get-UnifiWirelessNetwork.ps1' -1 function Get-UnifiWirelessNetwork { <# .SYNOPSIS Get wireless network configuration .DESCRIPTION Get wireless network configuration .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Get-UnifiWirelessNetwork -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { $headers = @{ "Accept"= "application/json" "Content-Type"= "application/json" } } process { $Api = "$($Url)/api/s/$($SiteName)/rest/wlanconf" try { $devices = Invoke-RestMethod -Headers $headers -Uri $Api -Method Get -WebSession $WebSession -ContentType 'application/json' -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Get-UnifiWirelessNetwork.ps1' 60 #Region './Public/Move-UnifiDevice.ps1' -1 function Move-UnifiDevice { <# .SYNOPSIS Move unifi device to another site .DESCRIPTION Move unifi device to another site .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteId Id of the site receiving the device. Use the '_id' property of the target site .PARAMETER SiteName Name of the source site. Use the 'name' property of the target site .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySourceSite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySourceSite' PS>$MyTargetSite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MyTargetSite' PS>Move-UnifiDevice -Url $Url -WebSession $session -SiteName $MySourceSite.name -SiteId $MyTargetSite.'_id' PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$SiteId, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "move-device" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Move Device")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/sitemgr" if($PSBoundParameters.containskey("SiteId")) { $Body["site_id"] = $SiteId } if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Move-UnifiDevice.ps1' 82 #Region './Public/Remove-UnifiBackup.ps1' -1 function Remove-UnifiBackup { <# .SYNOPSIS Remove specified backup file .DESCRIPTION Remove specified backup file .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER FileName Target device mac address .PARAMETER SiteName Use the 'name' property of the target site .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$backup = Get-UnifiBckup -Url $Url -WebSession $session | Where-Object {$( Get-Date -Date $_.datetime).tostring('yyyy-MM-dd') -ieq $(Get-Date -Format 'yyyy-MM-dd')} PS>Remove-UnifiBackup -Url $Url -WebSession $session -FileName $backup.filename PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName = 'default', [Parameter(Mandatory=$true)] [string]$FileName ) begin { [hashtable]$Body = @{ "cmd" = "delete-backup" } } process { if($PSCmdlet.ShouldProcess($FileName,"Remove Backup")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/backup" if($PSBoundParameters.containskey("FileName")) { $Body["filename"] = $FileName } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Remove-UnifiBackup.ps1' 73 #Region './Public/Remove-UnifiDevice.ps1' -1 function Remove-UnifiDevice { <# .SYNOPSIS Remove device from unifi .DESCRIPTION Remove device from unifi .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER MacAddress Target device mac address .PARAMETER SiteName Use the 'name' property of the target site .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$device = Get-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name | Where-Object {$_.hostname -ieq 'MyDevice'} PS>Remove-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "delete-device" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Remove Device")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/sitemgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Remove-UnifiDevice.ps1' 73 #Region './Public/Remove-UnifiSession.ps1' -1 function Remove-UnifiSession { <# .SYNOPSIS Destroys the target session. .DESCRIPTION Destroys the target session. .PARAMETER Url Target URL to the UNIFI controller .PARAMETER WebSession Target session .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>Remove-UnifiSession -Url $Url -WebSession $session #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession ) begin { $Api = "$($Url)/api/logout" } process { if($PSCmdlet.ShouldProcess("$($WebSession)","Remove session")) { try { $result = Invoke-WebRequest -Uri $Api -Method Post -ContentType 'application/json' -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop if($result.StatusCode -ne 200) { throw $result } } catch { throw $_.Exception.Message } } } end { return $UnifiSession } } #EndRegion './Public/Remove-UnifiSession.ps1' 53 #Region './Public/Remove-UnifiSite.ps1' -1 function Remove-UnifiSite { <# .SYNOPSIS Remove Site from unifi .DESCRIPTION Remove Site from unifi .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteId Use the '_id' property of the target site .PARAMETER SiteName Use the 'name' property of the target site .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Remove-UnifiSite -Url $Url -WebSession $session -SiteName $MySite.name -SiteId $MySite.'_id' PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$SiteId ) begin { [hashtable]$Body = @{ "cmd" = "delete-site" } } process { if($PSCmdlet.ShouldProcess($SiteName,"Remove Site")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/sitemgr" if($PSBoundParameters.containskey("SiteId")) { $Body["site"] = $SiteId } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Remove-UnifiSite.ps1' 72 #Region './Public/Reset-UnifiDpi.ps1' -1 function Reset-UnifiDpi { <# .SYNOPSIS Resets the site wide DPI counters .DESCRIPTION Resets the site wide DPI counters .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER MacAddress Target device mac address .PARAMETER SiteName Use the 'name' property of the target site .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$device = Get-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name | Where-Object {$_.hostname -ieq 'MyDevice'} PS>Reset-UnifiDpi -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { [hashtable]$Body = @{ "cmd" = "clear-dpi" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Remove Devie")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/stat" try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Reset-UnifiDpi.ps1' 68 #Region './Public/Restart-UnifiDevice.ps1' -1 function Restart-UnifiDevice { <# .SYNOPSIS Restarts unifi device .DESCRIPTION Restarts unifi device .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER MacAddress Target device mac address .PARAMETER SiteName Use the 'name' property of the target site .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$device = Get-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name | Where-Object {$_.hostname -ieq 'MyDevice'} PS>Restart-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "restart" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Remove Devie")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Restart-UnifiDevice.ps1' 73 #Region './Public/Restart-UnifiSwitchPort.ps1' -1 function Restart-UnifiSwitchPort { <# .SYNOPSIS Power cycles port on the target manged switch .DESCRIPTION Restarts a port on the target manged switch .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER MacAddress Target device mac address .PARAMETER SiteName Use the 'name' property of the target site .PARAMETER Port Target port on the switch .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$device = Get-UnifiDevice -Url $Url -WebSession $session -SiteName $MySite.name | Where-Object {$_.hostname -ieq 'MyDevice'} PS>Restart-UnifiSwitchPort -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $device.mac -Port $Device.downlink_table.port_idx PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress, [Parameter(Mandatory=$true)] [int]$Port ) begin { [hashtable]$Body = @{ "cmd" = "power-cycle" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Restart Switch Port")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } if($PSBoundParameters.containskey("Port")) { $Body["port_idx"] = $Port } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Restart-UnifiSwitchPort.ps1' 81 #Region './Public/Set-UnifiDeviceLedToNormal.ps1' -1 function Set-UnifiDeviceLedToNormal { <# .SYNOPSIS Set LED back to a normal state. .DESCRIPTION Set LED back to a normal state. .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device's mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Set-UnifiDeviceLedToNormal -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "unset-locate" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Set LED to Normal")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Set-UnifiDeviceLedToNormal.ps1' 70 #Region './Public/Start-UnifiAccessPointSpectrumScan.ps1' -1 function Start-UnifiAccessPointSpectrumScan { <# .SYNOPSIS Start RF scan on target access point .DESCRIPTION Start RF scan on target access point .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Start-UnifiAccessPointSpectrumScan -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "spectrum-scan" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Start RF scan")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Start-UnifiAccessPointSpectrumScan.ps1' 69 #Region './Public/Start-UnifiDeviceAdoption.ps1' -1 function Start-UnifiDeviceAdoption { <# .SYNOPSIS Adopts unifi device to the site network .DESCRIPTION Adopts unifi device to the site network .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Start-UnifiDeviceAdoption -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "adopt" } } process { if($pscmdlet.ShouldProcess($MacAddress,"Adop device")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Start-UnifiDeviceAdoption.ps1' 69 #Region './Public/Start-UnifiDeviceProvision.ps1' -1 function Start-UnifiDeviceProvision { <# .SYNOPSIS Force provision .DESCRIPTION Force provision .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Start-UnifiDeviceProvision -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "force-provision" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Force provision")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Start-UnifiDeviceProvision.ps1' 69 #Region './Public/Start-UnifiSiteSpeedTest.ps1' -1 function Start-UnifiSiteSpeedTest { <# .SYNOPSIS Start a speed test on target site .DESCRIPTION Start a speed test on target site .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Start-UnifiSiteSpeedTest -Url $Url -WebSession $session -SiteName $MySite.name PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName ) begin { [hashtable]$Body = @{ "cmd" = "speedtest" } } process { if($PSCmdlet.ShouldProcess($SiteName),"Start speed test") { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Start-UnifiSiteSpeedTest.ps1' 61 #Region './Public/Unblock-UnifiClient.ps1' -1 function Unblock-UnifiClient { <# .SYNOPSIS Unblocks a client from accessing the network .DESCRIPTION Unblocks a client from accessing the network .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Unblock-UnifiClient -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "unblock-sta" } } process { $Api = "$($Url)/api/s/$($SiteName)/cmd/stamgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } end { return $Output } } #EndRegion './Public/Unblock-UnifiClient.ps1' 71 #Region './Public/Update-UnifiDeviceFirmware.ps1' -1 function Update-UnifiDeviceFirmware { <# .SYNOPSIS Upgrade the firmware on target device .DESCRIPTION Upgrade the firmware on target device .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site ID. Use the 'name' property of the target site. .PARAMETER MacAddress Target device's mac address .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>$Device = Get-UnifiConnectedClient -Url $Url -WebSession $session -SiteName $MySite.name | where-object {$_.hostname -ieq 'MyDvice'} PS>Update-UnifiDeviceFirmware -Url $Url -WebSession $session -SiteName $MySite.name -MacAddress $Device.mac PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$MacAddress ) begin { [hashtable]$Body = @{ "cmd" = "upgrade" } } process { if($PSCmdlet.ShouldProcess($MacAddress,"Update Firmware")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/devmgr" if($PSBoundParameters.containskey("MacAddress")) { $Body["mac"] = $MacAddress } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Update-UnifiDeviceFirmware.ps1' 70 #Region './Public/Update-UnifiSite.ps1' -1 function Update-UnifiSite { <# .SYNOPSIS Updates the Desc of a site .DESCRIPTION Updates the Desc of a site .PARAMETER Url Target UniFi Url .PARAMETER WebSession UniFi web session .PARAMETER SiteName Target site name. .PARAMETER SiteDesc New site target description. Usually the customer's domain short name. .EXAMPLE PS>$Credential = $(Get-SecureCredential -Name 'Unifi' -VaultName 'MyVault') PS>$Url = "https://unifi.domain.com:8443" PS>$session = Get-UnifiSession -Url $Url -Credential $Credential PS>$MySite = Get-UnifiSite -Url $Url -WebSession $session -SiteName 'MySite' PS>Update-UnifiSite -Url $Url -WebSession $session -SiteName $MySite.name -SiteDesc 'MyUpdatedSite' PS>Remove-UnifiSession -Url $Url -WebSession $session -Confirm:$false #> [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [Alias("name")] [string]$SiteName, [Parameter(Mandatory=$true)] [string]$SiteDesc ) begin { [hashtable]$Body = @{ "cmd" = "update-site" } } process { if($PSCmdlet.ShouldProcess($SiteName, "Update Site")) { $Api = "$($Url)/api/s/$($SiteName)/cmd/sitemgr" if($PSBoundParameters.containskey("SiteDesc")) { $Body["desc"] = $SiteDesc } try { $devices = Invoke-RestMethod -Uri $Api -Method Post -ContentType 'application/json' -Body $($Body | ConvertTo-Json -Depth 99) -WebSession $WebSession -SkipCertificateCheck -ErrorAction Stop } catch { throw $_.Exception.Message } $Output = $devices.data } } end { return $Output } } #EndRegion './Public/Update-UnifiSite.ps1' 71 |