0

I have a piece of code which generates a CSV of sharenames from a filer.

Its a tab-delimited CSV and is just the sharenames, no other details are included.

I'd like to take the output:

010
2012 Comp
2012 Comp Plan Team

And replace it with this:

\\<filer>\010
\\<filer>\2012 Comp
\\<filer>\2012 Comp Plan Team

Right now I have the following:

$Content = import-csv C:\temp\new.txt -Delimiter "`t"

Can I use an Add-Member command to add in the new property/values to the array? Or am I going about this the wrong way?


The comments have been great so far, thanks guys. I forgot to add another point to this. I was wondering how I might add another column to the csv? Strictly for filer names. I'm thinking of producing a massive csv of share names and filer names. So just wanted to know how I could add that into it?

4

2 回答 2

0

不导入-CSV。但是,你应该使用Get-Content,IMO。

$content = Get-Content C:\test.csv
$content | ForEach-Object { '\\<filer>\'+$_ } | Set-Content C:\new-Test.csv
于 2013-07-23T18:27:23.427 回答
0

如果您显示的是文件的唯一内容,则无需费心Import-Csv,只需使用Get-Content

(Get-Content 'C:\temp\new.txt') -replace '^', '\\<filer>\'

以上仅产生一个字符串数组。要使其成为具有 2 列的 CSV,您可以做几件事,例如将字符串数组转换为具有相同 2 个属性的对象数组:

(Get-Content 'C:\temp\new.txt') -replace '^', '\\<filer>\' |
  select @{n='Path';e={$_}}, @{n='col2';e={...}}

或附加,something到字符串并将数组转换为 CSV:

(Get-Content 'C:\temp\new.txt') -replace '^', '\\<filer>\' -replace '$', ',...' |
  ConvertFrom-Csv
于 2013-07-23T18:29:20.190 回答