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

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






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

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

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

Hi, welcome to the forum :wave:

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.

1 Like

Alex,
Welcome to the forum. :wave:t4:

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. :wink:

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

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