gpt4 book ai didi

powershell - 替换导入的CSV文件中的字符串

转载 作者:行者123 更新时间:2023-12-03 00:28:08 24 4
gpt4 key购买 nike

我需要导入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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com