使用csv作为输入运行powershell命令 [英] run powershell command using csv as input
本文介绍了使用csv作为输入运行powershell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似
名称,电子邮件地址
姓名,电子邮件, br>
名称,电子邮件,地址
Name, email, address
Name, email, address
Name, email, address
我想要运行
-Mailbox -Name* Name *-WindowsLiveID * email * -ImportLiveId
(其中 * x * / code>被csv文件中的每一行中的csv的值替换。
(where *x*
is replaced by the value from the csv).
。
我如何做到这一点?
推荐答案
$csv = Import-Csv c:\path\to\your.csv
foreach ($line in $csv) {
New-Mailbox -Name $line.Name -WindowsLiveID $line.Email -ImportLiveId
}
csv的第一行必须是名称,电子邮件地址,地址
First line of csv has to be something like Name,Email,Address
如果您在CSV中没有标题,您也可以:
If you cannot have the header in the CSV, you can also have:
$csv = Import-Csv c:\path\to\your.csv -Header @("Name","Email","Address")
-Header不以任何方式修改csv文件。
-Header doesn't modify the csv file in any way.
这篇关于使用csv作为输入运行powershell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文