Skip to content

Instantly share code, notes, and snippets.

@markhallen
Last active October 31, 2018 09:00
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 markhallen/357b751213d9622f07991a0eabcba970 to your computer and use it in GitHub Desktop.
Save markhallen/357b751213d9622f07991a0eabcba970 to your computer and use it in GitHub Desktop.
class CommandString {
[String]$Command
CommandString([String]$Command)
{
$this.Command = $Command
}
[String] ToUninstall()
{
$Result = $this
$Result.Command = $Result.CaseInsensitiveReplace(" /install"," /uninstall")
$Result.Command = $Result.CaseInsensitiveReplace(" /modify"," /uninstall")
$Result.Command = $Result.CaseInsensitiveReplace(" /i "," /x ")
$Result.Command = $Result.CaseInsensitiveReplace(" /f "," /x ")
$Result.Command = $Result.Append(" /quiet")
$Result.Command = $Result.Append(" /norestart")
Return $Result.Command
}
[String] CaseInsensitiveReplace($Find,$Replace)
{
$Result = $this.Command
if($Result.ToLower().Contains($Find)) {
$Result = [Regex]::Replace(`
$Result, `
[regex]::Escape($Find), `
$Replace, `
[System.Text.RegularExpressions.RegexOptions]::IgnoreCase);
}
Return $Result
}
[String] Append($Postfix)
{
$Result = $this.Command
if(!($Result.ToLower().Contains($Postfix))) { $Result = $Result + $Postfix }
Return $Result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment