Skip to content

Latest commit

 

History

History
185 lines (145 loc) · 4.34 KB

File metadata and controls

185 lines (145 loc) · 4.34 KB
external help file PSPublishModule-help.xml
Module Name PSPublishModule
online version https://github.com/EvotecIT/PSPublishModule
schema 2.0.0

Remove-Comments

SYNOPSIS

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

SYNTAX

FilePath (Default)

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

Content

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

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

EXAMPLE 1

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

Writes the cleaned content to the destination file.

EXAMPLE 2

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

Returns the processed content when no destination file is specified.

PARAMETERS

-Content

Raw file content to process.

Type: String
Parameter Sets: Content
Aliases: None
Possible values:

Required: True
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-DestinationFilePath

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

Type: String
Parameter Sets: FilePath, Content
Aliases: Destination, OutputFile, OutputFilePath
Possible values:

Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-DoNotRemoveSignatureBlock

Do not remove a signature block, if present.

Type: SwitchParameter
Parameter Sets: FilePath, Content
Aliases: None
Possible values:

Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-RemoveAllEmptyLines

Remove all empty lines from the content.

Type: SwitchParameter
Parameter Sets: FilePath, Content
Aliases: None
Possible values:

Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-RemoveCommentsBeforeParamBlock

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

Type: SwitchParameter
Parameter Sets: FilePath, Content
Aliases: None
Possible values:

Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-RemoveCommentsInParamBlock

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

Type: SwitchParameter
Parameter Sets: FilePath, Content
Aliases: None
Possible values:

Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-RemoveEmptyLines

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

Type: SwitchParameter
Parameter Sets: FilePath, Content
Aliases: None
Possible values:

Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-SourceFilePath

File path to the source file.

Type: String
Parameter Sets: FilePath
Aliases: FilePath, Path, LiteralPath
Possible values:

Required: True
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

  • None

OUTPUTS

  • System.Object

RELATED LINKS

  • None