我需要导入CSV文件,然后将完整的用户名domain\username
替换为username
。
以下几行有效,但我只收到修改后的用户名作为输出,而不是完整文件。
您能否提一些建议?
$TestFile = Import-Csv .\file.csv
$NewFile = $TestFile | ForEach-Object {$_."Username" -replace 'domain\\',''}
最佳答案
您可以对字符串数据执行替换,然后使用ConvertFrom-Csv
将其转换为对象。
$TestFile = (Get-Content .\file.csv) -replace 'domain\\',''
$NewFile = ConvertFrom-Csv $TestFile
关于powershell - 替换导入的CSV文件中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45963765/