Created
June 25, 2020 17:37
-
-
Save EmmanuelTsouris/9c985af9aa442452d569b6a261c15f6c to your computer and use it in GitHub Desktop.
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
param ( | |
$ScriptPath | |
) | |
# Formats the Script to you can paste it into a RunCommand or Automation Document | |
# Example: | |
# .\AdditionalExamples\Format-PSForDocument.ps1 -ScriptPath .\AdditionalExamples\Install-SSMS.ps1 | |
# Grab the script and remove blank lines and comments | |
$powershell = (Get-Content $ScriptPath | Where-Object {$_ -notlike '#*' -and $_ -notlike [string]::Empty}) | |
# Escape Slashes | |
$powershell = $powershell | ForEach-Object {$_.Replace('\','\\')} | |
# Escape the double quote " with \", and then wrap the line in quotes with a comma on the end | |
$powershell = $powershell | ForEach-Object {$_.Replace('"','\"')} | ForEach-Object {"""$_"","} | |
# Remove the last comma | |
$powershell[$powershell.Length-1] = $powershell[$powershell.Length-1].TrimEnd(",") | |
Set-Clipboard -Value $powershell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment