Skip to content

Get-HostFirewallException

VMware: Retrieves the exceptions from the firewall policy on the specified host

#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [Parameter(Mandatory = $true)]
    [string]$HostName,
    [int32]$PortNumber,
    [bool]$Enabled
)
Process {
    $vmServer = $null
    try {
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        $vmHost = Get-VMHost -Server $vmServer -Name $HostName -ErrorAction Stop
        if ($PortNumber -gt 0) {
            $result = Get-VMHostFirewallException -Server $vmServer -VMHost $vmHost -Enabled $Enabled -Port $PortNumber -ErrorAction Stop | Select-Object *
        }
        else {
            $result = Get-VMHostFirewallException -Server $vmServer -VMHost $vmHost -Enabled $Enabled -ErrorAction Stop | Select-Object *
        }
        foreach ($item in $result) {
            $item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
            Write-Output $item
        }
    }
    catch { throw }
    finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}

IP address or DNS name of the vSphere server

PSCredential object for authenticating with the server

Host for which to retrieve firewall exceptions

Filter by port number

Filter to only retrieve enabled exceptions

An interactive directory of PowerShell scripts.