0

I need to import a CSV file and then replace the string domain\username AND the string domain\login with the word SSO.

I know that replacing only domain\username would be:

(Get-Content $ImportCPUFile) |
    ForEach-Object { $_ -replace '"domain\username"', '"sso"' } |
    Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii

But how to make an OR statement in the ForEach-Object function for domain\username and domain\login? I tried:

(Get-Content $ImportCPUFile) |
    ForEach-Object {$_ -replace '"domain\username"', '"sso"' -or $_ -replace '"domain\login"', '"sso"'} |
    Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii

But it returns only TRUE statements.

1 Answer 1

1

Try RegEx or '|'

(Get-Content $ImportCPUFile) |
ForEach-Object { $_ -replace '"domain\\username"|"domain\\login"', '"sso"' } |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii
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.