# Removing characters from a string with -replace

**URL:** https://forums.powershell.org/t/removing-characters-from-a-string-with-replace/2114
**Category:** PowerShell Help
**Created:** [December 1, 2013, 6:27am UTC](https://forums.powershell.org/t/removing-characters-from-a-string-with-replace/2114 "2013-12-01T06:27:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![barry-thomson](https://avatars.discourse-cdn.com/v4/letter/b/ecb155/32.png) [@barry-thomson](https://forums.powershell.org/u/barry-thomson)
#### Post date: [December 1, 2013, 6:27am UTC](https://forums.powershell.org/t/removing-characters-from-a-string-with-replace/2114/1 "2013-12-01T06:27:21Z")

</div>

Hi,

I’m trying to use this to change the output of the line below from Computername\Username, to simply Username  
Get-wmiobject win32\_computersystem | select username

When I use the code below, the output is @{username=\Username}

$User= get-wmiobject win32\_computersystem -computer $ComputerName2.text | select username  
$ID= $User-replace “Computername”, “”

Where am I going wrong on this one?

Thanks

---

<div class="post-metadata">

### Author: ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)
#### Post date: [December 1, 2013, 6:31am UTC](https://forums.powershell.org/t/removing-characters-from-a-string-with-replace/2114/2 "2013-12-01T06:31:53Z")

</div>

That’s because $user isn’t a string. It’s an object having a Username property (you could see that if you piped it to Get-Member). If, instead, you did “select-object -expand username” then you’d get the behavior you expected. -Expand extracts the CONTENT of the property, in this case returning a simple string.

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/removing-characters-from-a-string-with-replace/2114/3 "2024-05-16T20:52:34Z")

</div>


