run powershell command using csv as input

后端 未结 3 781
我寻月下人不归
我寻月下人不归 2021-02-02 00:55

I have a csv that looks like

Name, email, address
Name, email, address
Name, email, address

I am wanting to run

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 01:21

    $csv = Import-Csv c:\path\to\your.csv
    foreach ($line in $csv) {
        New-Mailbox -Name $line.Name -WindowsLiveID $line.Email -ImportLiveId
    }
    

    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:

    $csv = Import-Csv c:\path\to\your.csv -Header @("Name","Email","Address")
    

    -Header doesn't modify the csv file in any way.

提交回复
热议问题