首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell - Import-Csv逐行

Powershell - Import-Csv逐行
EN

Stack Overflow用户
提问于 2018-02-16 05:04:59
回答 1查看 246关注 0票数 0

我目前正在尝试使用导入CSV将数据导入到网站中,我正在导入的CSV如下:

代码语言:javascript
复制
Yes Test    Test    Test            test@test.com   test    test    test    test    test    Yes Yes Yes Yes Yes Yes Yes 1   
Yes test2   test2   test2           test2@test2.com test2   test2   test2   test2   test2   Yes Yes Yes Yes Yes Yes Yes 2

我面临的问题是,如果您以第二列为例,它将同时接受"Test“和"Test2”,并将其放入字段中,如下所示:

我正在努力寻找一种逐行进行的方法。

代码语言:javascript
复制
$Header = 'Active Contact', 'First Name', 'Last Name', 'Position', 'Office', 'Mobile', 'Email Address', 'Site Name', 'Town', 'County', 'Authorised to make changes to this list?', 'Change', 'Commercial', 'Planned / Emergency Maintenance Notification?', 'Major Incident Notification?', 'Priority 1 Notification?', 'View All Portal Tickets?', 'Excalation', 'Contact'

function Create-Contact { 
    $products = import-csv 'C:\Users\Test\Desktop\CACL.csv' -Header $Header | Select -Skip 8
    ForEach-Object {
        write-host "Working on Contact: $iterator "

        #fill out form fields
        ($ie.document.getElementById("106009280") |select -first 1).value = $products.'First Name'; #Forename
        ($ie.document.getElementById("106009237") |select -first 1).value = $products.'Last Name'; #Surname
        ($ie.document.getElementById("106009289") |select -first 1).value = $products.'Position'; #Job Title
        ($ie.document.getElementById("106009283") |select -first 1).value = $products.'Office'; #Telephone
        ($ie.document.getElementById("106009286") |select -first 1).value = $products.'Mobile'; #Mobile
        ($ie.document.getElementById("106009416") |select -first 1).value = $products.'Email Address'; #Email

        Start-Sleep -Seconds 5; # Remove For Prod

        ($ie.document.getElementById("updateBtn") |select-first 1).click #Submit the new contact

        Start-Sleep -Seconds 5; # Remove For Prod

        $iterator ++

    }
}
Create-Contact
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-16 05:36:05

$products是一个数组。当您访问保存在数组中的对象的成员时,powershell将返回包含这些值的数组。所以

代码语言:javascript
复制
$products.'First Name'

返回一个包含2个字符串的数组(即“测试Test2")

根据您的注释,在本例中,您可以通过索引来访问$products数组的各个行:

代码语言:javascript
复制
$products[0].'First Name'

将返回"Test“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48816254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档