Why does Get-Help not work on my script?

This is my script:

<#   
.SYNOPSIS
x
.Description
x
.PARAMETER vCenterName
x
.PARAMETER TargetEmailAddress
x
.PARAMETER SMTPServer
x
.EXAMPLE
x
.EXAMPLE
x
.EXAMPLE
x
.INPUTS
x
.OUTPUTS
x
.NOTES
x
.LINK
x
#>
Function Remove-OldFiles 
    {
    
    }

# Basic code to start the cull.
Write-Host "Script Starting." -ForegroundColor Green
$CurrPath = (Get-Location).path
Remove-OldFiles -FolderPath "$CurrPath\Test\" -FileFilter "ZertoReports_*.Log" -DaysOld 20 -WhatIf
Write-Host "Script Finished." -ForegroundColor Green

If I try this command:
get-help .\test.ps1

I get this back:
test.ps1

If I change the “Function” to “xFunction” Get-Help works OK??

get-help .\test.ps1

NAME
C:\Users\jmilano\Documents\PowerShell_Scripts\test.ps1

SYNOPSIS
x

SYNTAX
C:\Users\jmilano\Documents\PowerShell_Scripts\test.ps1 []

What am I doing wrong?

Tested on:

Name Value


PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

and

Name Value


PSVersion 5.1.14393.8146
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
BuildVersion 10.0.14393.8146
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Hmmm, I added a blank line to the end of the script and it works now!?

Using VSC version:

Version: 1.101.2 (system setup)
Commit: 2901c5ac6db8a986a5666c3af51ff804d05af0d4
Date: 2025-06-24T20:27:15.391Z
Electron: 35.5.1
ElectronBuildId: 11727614
Chromium: 134.0.6998.205
Node.js: 22.15.1
V8: 13.4.114.21-electron.0
OS: Windows_NT x64 10.0.14393

This is documented behaviour:

If the first item in the script body (after the help) is a function declaration, there must be at least two blank lines between the end of the script help and the function declaration. Otherwise, the help is interpreted as being help for the function, not help for the script.

Without the blank lines you would need to do this:

PS E:\Temp> . .\test.ps1
PS E:\Temp> Get-Help Remove-OldFiles
4 Likes