Skip to content

Instantly share code, notes, and snippets.

@Goadstir
Created January 8, 2020 21:16
Show Gist options
  • Select an option

  • Save Goadstir/2037de9778a4f591a4e2f8df6c6aafb6 to your computer and use it in GitHub Desktop.

Select an option

Save Goadstir/2037de9778a4f591a4e2f8df6c6aafb6 to your computer and use it in GitHub Desktop.
PowerShell: Remove the curly braces surrounding a string, or any character from within a string using an option within these examples.
# Remove the Curly Braces from a string such as after getting PSChildName. E.g. {636D9115-E54E-4673-B992-B51A8F8DDC8B}
# Using trim :
"{636D9115-E54E-4673-B992-B51A8F8DDC8B}".trim('{}')
# Using multiple replace :
"{636D9115-E54E-4673-B992-B51A8F8DDC8B}".Replace('{','').Replace('}','')
# Using Replace with RegEx
"{636D9115-E54E-4673-B992-B51A8F8DDC8B}" -replace '\{(.*)\}','$1'
# Using pure RegEx :
"{636D9115-E54E-4673-B992-B51A8F8DDC8B}" -match '\{(.*)\}'
$Matches[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment