2016-08-14 49 views
-1

我每天都需要修改CSV以便我可以提供帳戶。它需要簡單的信息並創建新帳戶。我可以處理PowerShell在AD中創建帳戶,它正在修改CSV。我需要創建一個用戶名和一個電子郵件地址與其他文字。CSV中的複製和更改列

輸入看起來就像這樣:

First,Last,School,Attribute,Description 
John,Smith,Elementary,A2F,teacher 
Joe,Johnson,High School,A2F,teacher 
Greg,Harris,Middle School,A2F,teacher

輸出需要看起來像這樣:

First,Last,School,Attribute,Description,Username,Email 
John,Smith,Elementary,A2F,teacher,JSmith.sfo,[email protected] 
Joe,Johnson,High School,A2F,teacher,JJohnson.sfo,[email protected] 
Greg,Harris,Middle School,A2F,teacher,GHarris.sfo,[email protected]

回答

1

使用Select-Object與計算特性爲每個新列你想:

Import-Csv .\old.csv | 
Select-Object *,@{Name='Username';Expression={'{0}{1}.sfo' -f $_.First[0],$_.Last}},@{Name='Email';Expression={'{0}.{1}[email protected]' -f $_.First,$_.Last}} | 
Export-Csv .\new.csv -NoTypeInformation 
+0

天才。精美的作品。謝謝! –