0

I have this cmd script:

REM Environment-Variables which can be used for Programs
REM ----------------------------------------------------------------
set SDENVDataPool=13
set SDENVDataPoolPath=C:\ProgramData\

The value 13 must be changed. I have tried this solution:

$line = Get-Content .\script.cmd | Select-String -Pattern "set SDENVDataPool" | Select-Object -ExpandProperty Line
$content = Get-Content .\script.cmd
$content | ForEach-Object {$_ -replace $line, "set SDENVDataPool=14"} | Set-Content .\script.cmd

The problem is that the line isn't read correctly. I get the whole file.

Can anyone help me?

1 Answer 1

1

In your Select-String -Pattern "set SDENVDataPool" you are returning more than one line as both set SDENVDataPool=13 & set SDENVDataPoolPath=C:\ProgramData\ match that pattern. If you change your Pattern to Select-String -Pattern "set SDENVDataPool=" you should correctly return one match which you can then use in the rest of your script to set the content when you run this portion

$content | ForEach-Object {$_ -replace $line, "set SDENVDataPool=14"} | Set-Content .\script.cmd

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.