Skip to content

Instantly share code, notes, and snippets.

@EmmanuelTsouris
Created June 25, 2020 17:37
Show Gist options
  • Save EmmanuelTsouris/9c985af9aa442452d569b6a261c15f6c to your computer and use it in GitHub Desktop.
Save EmmanuelTsouris/9c985af9aa442452d569b6a261c15f6c to your computer and use it in GitHub Desktop.
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