"Get-Help" does not display contents

I'm trying to get "Get-Help" to display properly for this function. However, when I run the command, it just displays the help content for "Get-Help"

function OpenClosePorts { <# .SYNOPSIS Create, modify, or toggle a firewall rule

.DESCRIPTION Create, modify, or toggle a firewall rule Set the parameters for the new rule. If a rule with the specified name exists > Update the rule to match the new parameters If a rule with the specified name does not exist > create a new firewall rule with the specified parameters

.PARAMETER DisplayName Specifies the name of the firewall rule to be modified

.PARAMETER LocalPort (Optional) Specify the port affected by the firewall rule

.PARAMETER Direction (Optional)Specify if the connection is Inbound or Outbound. (Default = Inbound)

.PARAMETER Action (Optional) Select if you want to Allow or Block a connection. (Default = Allow)

.PARAMETER Exists (Optional) Enable or Dissable the rule. True/False (Default = True) #> param ( [string]$DisplayName = "Test",$LocalPort = 8626, [string]$Direction = "Inbound",[string]$Action = "Allow",$Exists = $true ) $CheckRule = Get-NetFirewallRule -DisplayName $DisplayName 2> $null

if ($CheckRule){
    Set-NetFirewallRule -DisplayName $DisplayName `
    -LocalPort $LocalPort `
    -Direction $Direction `
    -Protocol TCP `
    -Action $Action `
    -Enabled $Exists.ToString()
    }
else {
    New-NetFirewallRule -DisplayName $DisplayName `
    -LocalPort $LocalPort `
    -Direction $Direction `
    -Protocol TCP `
    -Action $Action `
}

}

Upvotes: 2

Views: 70

Answers (1)

Jeter-work
Jeter-work

Reputation: 801

You need to load the function before it works with Get-Help.

There's various ways to load functions, but the simplest is to just run the script which defines the function. This only lasts as long as the session. Other ways include adding a script to your environment, meaning it will always load. You can research this if you are interested.

Once you run the script defining the function, Get-Help will work.

You do not have to run the function for Get-Help to work.

Upvotes: 1

Related Questions