powershell - 将相同的字符串附加到PowerShell中CSV列中的所有变量
问题描述
我需要有关如何将字符串添加-Config
到名称列中的每个名称的帮助。
CSV 文件包含:
FullName Name LastWriteTime
\\remotecomputer\ Henry 4/30/2020 3:44:57 PM
\\remotecompter\ Magy 12/7/2020 9:04:28 PM
所需的输出:
FullName Name LastWriteTime
\\remotecomputer\ Henry-Config 4/30/2020 3:44:57 PM
\\remotecompter\ Magy-Config 12/7/2020 9:04:28 PM
我当前的代码:
$InvoiceList = Import-CSV -Path C:\$source-PREP.csv | foreach($list in $InvoiceList){
$Name=$($list.name)
Get-ChildItem -Path 'C:\Names' -Filter *.txt | where {$_.Name -like '*' }|Copy-Item -Destination 'c:\newfolder' -Force }
解决方案
您只需要迭代 CSV 中的每一行并更新 name 属性。完成后导出回 CSV
$csvfile = 'some\path\to\file.csv'
$csvdata = Import-Csv $csvfile
$csvdata | ForEach-Object {$_.name = $_.name + '-Config'}
$csvdata | Export-Csv $csvfile -NoTypeInformation
推荐阅读
- vb.net - VB.net 用文件夹中的图像填充 Listview
- ruby-on-rails - has_many 通过 Rails REST API 中的关联
- javascript - 未捕获的数组类型错误
- java - Java:需要查看输入字符串中的每个字符是否与“字母表”中的任何字符匹配
- c - 读取另一个参数后如何修复命令行参数更改?
- css - 如何暂停或延迟闪烁的文本动画,以便我的文本显示一小段时间?
- asp.net - Asp.Net CodeFirst 如何在 3 个模型之间导航?
- python - 将列表转换为python数组
- html - 如何在我的网站上操作此元素
- javascript - XMLHttpRequest 返回未定义的响应,但适用于 console.log