替换导入的 CSV 文件中的字符串/多个条件
Replace string in an imported CSV file / multiple conditions
我需要导入 CSV 文件,然后将字符串 domain\username
和字符串 domain\login
替换为 SSO
.
我知道只替换 domain\username
会是:
(Get-Content $ImportCPUFile) |
ForEach-Object { $_ -replace '"domain\username"', '"sso"' } |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii
但是如何在ForEach-Object
函数中对domain\username
和domain\login
进行OR语句呢?我试过了:
(Get-Content $ImportCPUFile) |
ForEach-Object {$_ -replace '"domain\username"', '"sso"' -or $_ -replace '"domain\login"', '"sso"'} |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii
但它 returns 只有 TRUE 语句。
试试 RegEx 或“|”
(Get-Content $ImportCPUFile) |
ForEach-Object { $_ -replace '"domain\username"|"domain\login"', '"sso"' } |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii
我需要导入 CSV 文件,然后将字符串 domain\username
和字符串 domain\login
替换为 SSO
.
我知道只替换 domain\username
会是:
(Get-Content $ImportCPUFile) |
ForEach-Object { $_ -replace '"domain\username"', '"sso"' } |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii
但是如何在ForEach-Object
函数中对domain\username
和domain\login
进行OR语句呢?我试过了:
(Get-Content $ImportCPUFile) |
ForEach-Object {$_ -replace '"domain\username"', '"sso"' -or $_ -replace '"domain\login"', '"sso"'} |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii
但它 returns 只有 TRUE 语句。
试试 RegEx 或“|”
(Get-Content $ImportCPUFile) |
ForEach-Object { $_ -replace '"domain\username"|"domain\login"', '"sso"' } |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii