使用 csv 作为输入运行 powershell 命令
我有一个 csv 看起来像
姓名、电子邮件、地址
姓名、电子邮件、地址
姓名、电子邮件、地址
我想要运行的 New-Mailbox -Name "*Name*" -WindowsLiveID *email* -ImportLiveId
(其中 *x*
替换为 csv 中的值)。
在 csv 文件中的每一行。
我该怎么做?
I have a csv that looks like
Name, email, address
Name, email, address
Name, email, address
I am wanting to runNew-Mailbox -Name "*Name*" -WindowsLiveID *email* -ImportLiveId
(where *x*
is replaced by the value from the csv).
on each line in the csv file.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
csv 的第一行必须是姓名、电子邮件、地址之类的内容
如果 CSV 中无法包含标题,您还可以:
-标题不会以任何方式修改 csv 文件。
First line of csv has to be something like Name,Email,Address
If you cannot have the header in the CSV, you can also have:
-Header doesn't modify the csv file in any way.
这是我见过的一些最有用的信息 - 它让我的工作变得更加轻松!
组合 Netapp 命令:
从控制器获取卷、获取所述卷的快照计划并导出到 csv
:获取 NaSnapshotSchedule | Export-Csv -path d:\something.csv
以当前值导入 csv 读数并为每列分配一个标签。
对于每个对象,通过重新使用 5 个可用列/数据字段中的 4 个来创建新计划
import-csv d:\something.csv -header ("label1","label2","label3","label4","标签5") | foreach {Set-naSnapshotschedule $.label1 -周 $.label2 -天 $.label3 -小时 $.label4 -Whichhours "1,2,3,4,5" 好东西
!!!
请注意,“标签”应该有一个下划线 - 无论出于何种原因,它都没有反映在页面中,因此 Dollar($)Underscore(_)Dot(.)Label
This is some of the most useful information I have seen yet - it just made my job so much easier!!!
Combining Netapp commands:
get volumes from a controller, get snapshot schedule for said volumes, and export to a csv:
get-navol | Get-NaSnapshotSchedule | Export-Csv -path d:\something.csv
Import the csv reading in current values and assigning each column a label.
For each object, create a new schedule by RE-USING 4 of the 5 available columns/data fields
import-csv d:\something.csv -header ("label1","label2","label3","label4","label5") | foreach {Set-naSnapshotschedule $.label1 -Weeks $.label2 -Days $.label3 -Hours $.label4 -Whichhours "1,2,3,4,5"}
EXCELLENT STUFF!!!
Please note that the "Labels" should have an underscore - for whatever reason it isn't reflecting in the page so Dollar($)Underscore(_)Dot(.)Label