Evotec

Project

PSPublishModule

PSPublishModule is an open-source PowerShell and .NET project with packages, release history, and technical documentation.

Stars 43
Forks 13
Open issues 1
PowerShell Gallery downloads 13,876
Release v3.0.3
Language: C# Updated: 2026-04-14

API Reference

Cmdlet

Remove-Comments

Namespace PSPublishModule
Inputs
None
Outputs
System.Object

Removes PowerShell comments from a script file or provided content, with optional empty-line normalization.

Remarks

Uses the PowerShell parser (AST) to remove comments safely rather than relying on fragile regex-only approaches. Useful as a preprocessing step when producing merged/packed scripts.

Examples

Authored help example

Remove comments from a file and write to a new file

PS>


Remove-Comments -SourceFilePath '.\Public\Get-Thing.ps1' -DestinationFilePath '.\Public\Get-Thing.nocomments.ps1'
        

Writes the cleaned content to the destination file.

Remove comments from content and return the processed text

PS>


$clean = Remove-Comments -Content (Get-Content -Raw .\script.ps1)
        

Returns the processed content when no destination file is specified.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.

Syntax

Remove-Comments [-DestinationFilePath <String>] [-DoNotRemoveSignatureBlock] [-RemoveAllEmptyLines] [-RemoveCommentsBeforeParamBlock] [-RemoveCommentsInParamBlock] [-RemoveEmptyLines] -SourceFilePath <String> [<CommonParameters>]
#
Parameter set: FilePath

Parameters

DestinationFilePath String optionalposition: namedpipeline: Falsealiases: Destination, OutputFile, OutputFilePath
File path to the destination file. If not provided, the content is returned.
DoNotRemoveSignatureBlock SwitchParameter optionalposition: namedpipeline: False
Do not remove a signature block, if present.
RemoveAllEmptyLines SwitchParameter optionalposition: namedpipeline: False
Remove all empty lines from the content.
RemoveCommentsBeforeParamBlock SwitchParameter optionalposition: namedpipeline: False
Remove comments before the param block. By default comments before the param block are not removed.
RemoveCommentsInParamBlock SwitchParameter optionalposition: namedpipeline: False
Remove comments in the param block. By default comments in the param block are not removed.
RemoveEmptyLines SwitchParameter optionalposition: namedpipeline: False
Remove empty lines if more than one empty line is found.
SourceFilePath String requiredposition: namedpipeline: Falsealiases: FilePath, LiteralPath, Path
File path to the source file.

Outputs

System.Object

Remove-Comments -Content <String> [-DestinationFilePath <String>] [-DoNotRemoveSignatureBlock] [-RemoveAllEmptyLines] [-RemoveCommentsBeforeParamBlock] [-RemoveCommentsInParamBlock] [-RemoveEmptyLines] [<CommonParameters>]
#
Parameter set: Content

Parameters

Content String requiredposition: namedpipeline: False
Raw file content to process.
DestinationFilePath String optionalposition: namedpipeline: Falsealiases: Destination, OutputFile, OutputFilePath
File path to the destination file. If not provided, the content is returned.
DoNotRemoveSignatureBlock SwitchParameter optionalposition: namedpipeline: False
Do not remove a signature block, if present.
RemoveAllEmptyLines SwitchParameter optionalposition: namedpipeline: False
Remove all empty lines from the content.
RemoveCommentsBeforeParamBlock SwitchParameter optionalposition: namedpipeline: False
Remove comments before the param block. By default comments before the param block are not removed.
RemoveCommentsInParamBlock SwitchParameter optionalposition: namedpipeline: False
Remove comments in the param block. By default comments in the param block are not removed.
RemoveEmptyLines SwitchParameter optionalposition: namedpipeline: False
Remove empty lines if more than one empty line is found.

Outputs

System.Object