[英]Replace string in an imported CSV file / multiple conditions
I need to import a CSV file and then replace the string domain\username
AND the string domain\login
with the word SSO
.我需要导入一个 CSV 文件,然后将字符串
domain\username
和字符串domain\login
替换为单词SSO
。
I know that replacing only domain\username
would be:我知道仅替换
domain\username
名将是:
(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
?但是如何在
ForEach-Object
function 中为domain\username
和domain\login
做一个 OR 语句呢? 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.但它只返回 TRUE 语句。
Try RegEx or '|'尝试正则表达式或“|”
(Get-Content $ImportCPUFile) |
ForEach-Object { $_ -replace '"domain\\username"|"domain\\login"', '"sso"' } |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.