Remove string from string in PowerShell

Remove string from string in PowerShell

Q. How can I easily remove a string of text in PowerShell?

A. A simple way to remove a string from a string is to search for the string to be replaced and substitute with a blank string. For example to remove LAB I could use:

$LabShortName = $Lab.Name.Replace("LAB","")

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish