# Remove-Comments

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

Project

PSPublishModule

Build, test, version, sign, and publish PowerShell modules with reusable PowerForge pipelines.

[View on GitHub](https://github.com/EvotecIT/PSPublishModule) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSPublishModule/releases/tag/v3.0.124) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSPublishModule/2.0.27)

Stars **48**

Forks **15**

Open issues **1**

PowerShell Gallery downloads **17,213**

Release **v3.0.195**

Language: C# Updated: 2026-11-25

Command 

**Module**

`PSPublishModule`

**Inputs**

`None`

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

## Syntax

```
Remove-Comments
[-DestinationFilePath <String>]
[-DoNotRemoveSignatureBlock]
[-RemoveAllEmptyLines]
[-RemoveCommentsBeforeParamBlock]
[-RemoveCommentsInParamBlock]
[-RemoveEmptyLines]
-SourceFilePath <String>
[<CommonParameters>]
```

[#](#method-remove-comments-string-switchparameter-switchparameter-switchparameter-switchparameter-switchparameter-string)

Parameter set: `FilePath`

```
Remove-Comments
-Content <String>
[-DestinationFilePath <String>]
[-DoNotRemoveSignatureBlock]
[-RemoveAllEmptyLines]
[-RemoveCommentsBeforeParamBlock]
[-RemoveCommentsInParamBlock]
[-RemoveEmptyLines]
[<CommonParameters>]
```

[#](#method-remove-comments-string-string-switchparameter-switchparameter-switchparameter-switchparameter-switchparameter)

Parameter set: `Content`

## Description

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

### Remove comments from a file and write to a new file

```powershell
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

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

Returns the processed content when no destination file is specified.

## Parameters

**-DestinationFilePath String optionalaliases: Destination, OutputFile, OutputFilePath**

File path to the destination file. If not provided, the content is returned.

**-DoNotRemoveSignatureBlock SwitchParameter optional**

Do not remove a signature block, if present.

**-RemoveAllEmptyLines SwitchParameter optional**

Remove all empty lines from the content.

**-RemoveCommentsBeforeParamBlock SwitchParameter optional**

Remove comments before the param block. By default comments before the param block are not removed.

**-RemoveCommentsInParamBlock SwitchParameter optional**

Remove comments in the param block. By default comments in the param block are not removed.

**-RemoveEmptyLines SwitchParameter optional**

Remove empty lines if more than one empty line is found.

**-SourceFilePath String requiredaliases: FilePath, LiteralPath, Pathsets: FilePath**

File path to the source file.

**-Content String requiredsets: Content**

Raw file content to process.

## 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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

Evotec API Reference Copyright 2026 Evotec Services

<!-- PowerForge markdown artifact sha256:9510A59684FC53E2C9F6CE3C3DEE2944950D7F6F7D9DFF28B2900CDB5B78D1D5 -->
