Last active
February 12, 2023 15:32
-
-
Save sdcampbell/854788ad0a7a02b3ba105aa827dadc09 to your computer and use it in GitHub Desktop.
Remove all comments from PowerShell scripts. Copied from https://github.com/FortyNorthSecurity/RandomScripts/blob/main/Cobalt%20Scripts/remove_comments.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
#remove comments from PowerShell scripts | |
currently_code = True | |
with open(sys.argv[1], 'r') as readtest: | |
psup_contents = readtest.readlines() | |
with open(sys.argv[1], 'w') as removed: | |
for line in psup_contents: | |
line = line.lstrip() | |
if line.startswith("#") and not line.startswith("#>"): | |
pass | |
elif line.startswith("<#"): | |
currently_code = False | |
elif line.startswith('\n'): | |
pass | |
elif line.startswith("#>"): | |
currently_code = True | |
else: | |
if currently_code: | |
removed.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment