csv 有一个列,Install_Location。我想使用该 Instanll_Location 并将 \temp 附加到它
我无法提取 Install_Locations 的该行并向其添加附加路径。
$Sourcefile = "C:\File.csv"
$StartProperties = (Import-Csv $Sourcefile)
$Sorted = $StartProperties |select Server_Name, Service_Name, Install_Location | ? Service_Name -like *DISP* | Sort-Object -Property Server_Name
$Sorted
$TempDumps = "$($_.Install_Location)\temp"
$TempDumps
cmdlet DumpCleanup at command pipeline position 1
Supply values for the following parameters:
Server_Name: TEST
Server_Name Service_Name Install_Location
----------- ------------ ----------------
DEFRCOGAPP101 IBM Cognos Analytics DISP03:9300 D$\Program Files\ibm\cognos\analytics\DISP03
DEFRCOGAPP101 IBM Cognos Analytics DISP09:9900 D$\Program Files\ibm\cognos\analytics\DISP09
DEFRCOGAPP101 IBM Cognos Analytics DISP04:9400 D$\Program Files\ibm\cognos\analytics\DISP04
DEFRCOGAPP101 IBM Cognos Analytics DISP05:9500 D$\Program Files\ibm\cognos\analytics\DISP05
DEFRCOGAPP101 IBM Cognos Analytics DISP06:9600 D$\Program Files\ibm\cognos\analytics\DISP06
DEFRCOGAPP101 IBM Cognos Analytics DISP07:9700 D$\Program Files\ibm\cognos\analytics\DISP07
DEFRCOGAPP101 IBM Cognos Analytics DISP08:9800 D$\Program Files\ibm\cognos\analytics\DISP08
DEFRCOGAPP101 IBM Cognos Analytics DISP02:9200 D$\Program Files\ibm\cognos\analytics\DISP02
DEFRCOGAPP101 IBM Cognos Analytics DISP01:9100 D$\Program Files\ibm\cognos\analytics\DISP01
DEFRCOGAPP101 IBM Cognos Analytics DISP10:10000 D$\Program Files\ibm\cognos\analytics\DISP10
答案1
互联网上有大量关于该主题的信息。
本文基本上告诉你你需要做什么,这是你在谷歌搜索“edit csv PowerShell”时找到的第一个
您需要执行以下步骤:
- 导入 CSV
- 循环遍历 CSV
- 根据条件更改参数,或者根据您的情况添加参数
- 返回整个对象
- 导出
以下是遵循这些步骤的代码。注意:它将覆盖源 CSV。如果您不想覆盖它,请在Export-CSV
$CSV = "C:\File.csv"
@(Import-Csv $CSV) | ForEach-Object {
$_.Install_Location += "\temp"
$_
} | Export-Csv $CSV -Force -NoTypeInformation