Last active
August 7, 2020 17:11
-
-
Save IvanStoychev/51fa69a24bd242bfa6a6c2b5954832a7 to your computer and use it in GitHub Desktop.
Powershell scripts
This file contains 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
A collection of scripts, each serving a purpose to lighten a programmer's load and/or automate some process to an extent. |
This file contains 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
# 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 "&xml<data'yay>" | |
$x = Get-Clipboard | |
$EscapeCharactersMap = @{} | |
$EscapeCharactersMap["&"] = "&" | |
$EscapeCharactersMap["<"] = "<" | |
$EscapeCharactersMap[">"] = ">" | |
$EscapeCharactersMap["'"] = "'" | |
$EscapeCharactersMap['"'] = """ | |
foreach($key in $EscapeCharactersMap.Keys) | |
{ $x = $x -replace $key, $EscapeCharactersMap[$key] } | |
Set-Clipboard -Value $x |
This file contains 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
# 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 "&xml<data'yay>" | |
$x = Get-Clipboard | |
$SpecialSymbolsMap = @{} | |
$SpecialSymbolsMap["&"] = "&" | |
$SpecialSymbolsMap["<"] = "<" | |
$SpecialSymbolsMap[">"] = ">" | |
$SpecialSymbolsMap["'"] = "'" | |
$SpecialSymbolsMap["""] = '"' | |
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