我目前正在尝试使用导入CSV将数据导入到网站中,我正在导入的CSV如下:
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”,并将其放入字段中,如下所示:

我正在努力寻找一种逐行进行的方法。
$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发布于 2018-02-16 05:36:05
$products是一个数组。当您访问保存在数组中的对象的成员时,powershell将返回包含这些值的数组。所以
$products.'First Name'返回一个包含2个字符串的数组(即“测试Test2")
根据您的注释,在本例中,您可以通过索引来访问$products数组的各个行:
$products[0].'First Name'将返回"Test“。
https://stackoverflow.com/questions/48816254
复制相似问题