# Replace =/s, why it doesn't work?

**URL:** <https://forums.powershell.org/t/replace-s-why-it-doesnt-work/21051>\
**Category:** PowerShell Help\
**Created:** [November 30, 2022, 9:00pm UTC](https://forums.powershell.org/t/replace-s-why-it-doesnt-work/21051 "2022-11-30T21:00:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![emufile](https://avatars.discourse-cdn.com/v4/letter/e/a587f6/32.png) [@emufile](https://forums.powershell.org/u/emufile)\
**Post date:** [November 30, 2022, 9:00pm UTC](https://forums.powershell.org/t/replace-s-why-it-doesnt-work/21051/1 "2022-11-30T21:00:51Z")

</div>

Hello everyone,  
emu is speaking  
the sky are blue, the wind icing and i’m hitting the head on the desk by 2 hours  
Stupid script…i have this file

```auto

Caption=

CSName=DC01

Description=Security Update

FixComments=

HotFixID=KB5020374

InstallDate=

InstalledBy=NT AUTHORITY\SYSTEM

InstalledOn=11/11/2022

Name=

ServicePackInEffect=

Status=

```

For Example i need to replace Name= with Name=none (the same for status and service pack)  
I’m trying to use this

```auto
(Get-Content -Path c:\ps\file.txt) | ForEach-Object {$_ -Replace '=\s','=NONE'} | Out-File c:\ps\file2.txt

```

The script run but nothing happen ☹  
Where a make mistake?  
Thank you very much

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [November 30, 2022, 9:24pm UTC](https://forums.powershell.org/t/replace-s-why-it-doesnt-work/21051/2 "2022-11-30T21:24:37Z")

</div>

Hi, welcome to the forum 👋

Your regular expression `'=\s'` looks for the equals sign followed by a single whitespace character so it doesn’t match anything.

Try using `'=$'` which will match any equals sign at the end of a line.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 30, 2022, 9:24pm UTC](https://forums.powershell.org/t/replace-s-why-it-doesnt-work/21051/3 "2022-11-30T21:24:59Z")

</div>

Alex,  
Welcome to the forum. 👋🏽

The issue with your code or your input file is - you actually don’t have a white space after the equal sign - it is the end of the according string. 😉

So something like this should work the way you probably expect it:

```auto
Get-Content -Path c:\ps\file.txt | 
    ForEach-Object {
        $_ -Replace '=$','=NONE'
    } | 
        Out-File c:\ps\file2.txt

```

---

<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:16pm UTC](https://forums.powershell.org/t/replace-s-why-it-doesnt-work/21051/4 "2024-05-16T20:16:19Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


