Strips comments and extra whitespace from a script.
PowerSploit Function: Remove-Comment
Author: Matthew Graeber (@mattifestation)
License: BSD 3-Clause
Required Dependencies: None
Optional Dependencies: None
Remove-Comment [-Path] <String>
Remove-Comment [-ScriptBlock] <ScriptBlock>
Remove-Comment strips out comments and unnecessary whitespace from a script. This is best used in conjunction with Out-EncodedCommand when the size of the script to be encoded might be too big.
A major portion of this code was taken from the Lee Holmes' Show-ColorizedContent script. You rock, Lee!
$Stripped = Remove-Comment -Path .\ScriptWithComments.ps1
Remove-Comment -ScriptBlock {
My documentation is beyond reproach! Write-Host 'Hello, World!' ### Write 'Hello, World' to the host
}
Write-Host 'Hello, World!'
Remove-Comment -Path Inject-Shellcode.ps1 | Out-EncodedCommand
Removes extraneous whitespace and comments from Inject-Shellcode (which is notoriously large) and pipes the output to Out-EncodedCommand.
Specifies the path to your script.
Type: String
Parameter Sets: FilePath
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies a scriptblock containing your script.
Type: ScriptBlock
Parameter Sets: ScriptBlock
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseAccepts either a string containing the path to a script or a scriptblock.
Remove-Comment returns a scriptblock. Call the ToString method to convert a scriptblock to a string, if desired.