Skip to content

Instantly share code, notes, and snippets.

@IvanStoychev
Last active August 7, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanStoychev/51fa69a24bd242bfa6a6c2b5954832a7 to your computer and use it in GitHub Desktop.
Save IvanStoychev/51fa69a24bd242bfa6a6c2b5954832a7 to your computer and use it in GitHub Desktop.
Powershell scripts
A collection of scripts, each serving a purpose to lighten a programmer's load and/or automate some process to an extent.
# This script takes the contents of the clipboard and replaces any XML special characters in it with their escaped versions.
# The mapping is achieved by the use of the "EscapeCharactersMap" hashtable.
# To use the script - simply copy the text with special characters (no need to paste it anywhere) and run the script.
# Example:
# 1. Clipboard text is "&xml<data'yay>".
# 2. Script is run.
# 3. Clipboard text is now "&amp;xml&lt;data&apos;yay&gt;"
$x = Get-Clipboard
$EscapeCharactersMap = @{}
$EscapeCharactersMap["&"] = "&amp;"
$EscapeCharactersMap["<"] = "&lt;"
$EscapeCharactersMap[">"] = "&gt;"
$EscapeCharactersMap["'"] = "&apos;"
$EscapeCharactersMap['"'] = "&quot;"
foreach($key in $EscapeCharactersMap.Keys)
{ $x = $x -replace $key, $EscapeCharactersMap[$key] }
Set-Clipboard -Value $x
# This script takes the contents of the clipboard and replaces any XML escape characters in it with their symbol counterparts.
# The mapping is achieved by the use of the "SpecialSymbolsMap" map.
# To use the script - simply copy the text with special characters (no need to paste it anywhere) and run the script.
# Example:
# 1. Clipboard text is "&xml<data'yay>".
# 2. Script is run.
# 3. Clipboard text is now "&amp;xml&lt;data&apos;yay&gt;"
$x = Get-Clipboard
$SpecialSymbolsMap = @{}
$SpecialSymbolsMap["&amp;"] = "&"
$SpecialSymbolsMap["&lt;"] = "<"
$SpecialSymbolsMap["&gt;"] = ">"
$SpecialSymbolsMap["&apos;"] = "'"
$SpecialSymbolsMap["&quot;"] = '"'
foreach($key in $SpecialSymbolsMap.Keys)
{ $x = $x -replace $key, $SpecialSymbolsMap[$key] }
Set-Clipboard -Value $x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment