powershell Powershell脚本,用于从CSV中提取数据并将其放入SharePoint列表中。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Powershell脚本,用于从CSV中提取数据并将其放入SharePoint列表中。相关的知识,希望对你有一定的参考价值。
Add-PsSnapin Microsoft.SharePoint.PowerShell
# CSV path/File name
$contents = Import-Csv "c:\temp\MarketingSupply.csv"
# Web URL
$web = Get-SPWeb -Identity "http://scushp01/marketing"
# SPList name
$list = $web.Lists["MarketingSupplyItems"]
# Iterate for each list column
$i = 1
foreach ($row in $contents) {
$i
$i++
$item = $list.Items.Add();
$item["SupplyCategory"] = $row.SupplyCategory;
$item["SupplyItemName"] = $row.SupplyItemName;
$item["SupplyItemPicture"] = $row.SupplyItemPicture;
$item.Update();
}
Add-PsSnapin Microsoft.SharePoint.PowerShell
# CSV path/File name
$contents = Import-Csv "c:\temp\Branch.csv"
# Web URL
$web = Get-SPWeb -Identity "http://scushp01"
# SPList name
$list = $web.Lists["Branches"]
# Iterate for each list column
$i = 1
foreach ($row in $contents) {
$i
$i++
$item = $list.Items.Add();
$item["Title"] = $row.BranchName;
$item["BranchNumber"] = $row.BranchNumber;
$item["Address"] = $row.Address;
$item["City"] = $row.City;
$item["State"] = $row.State;
$item["Country"] = $row.Country;
$item["ZipCode"] = $row.ZipCode;
$item.Update();
}
# CSV path/File name
$contents = Import-Csv "c:\temp\jduty.csv"
# Web URL
$web = Get-SPWeb -Identity "http://scushp01/sites/Testing/"
# SPList name
$list = $web.Lists["JobDuties"]
# Iterate for each list column
$i = 1
foreach ($row in $contents) {
$i
$i++
$item = $list.Items.Add();
$item["Dept"] = $row.Dept;
$item["DeptExt"] = $row.DeptExt;
$item["Employee"] = $row.Employee;
$item["EmployeeExt"] = $row.EmployeeExt;
$item["Duty"] = $row.Duty;
$item.Update();
}
以上是关于powershell Powershell脚本,用于从CSV中提取数据并将其放入SharePoint列表中。的主要内容,如果未能解决你的问题,请参考以下文章
SQLServer用powershell实现多台服务器批量执行SQL脚本
利用 Powershell 编写简单的浏览器脚本
PowerShell脚本授权最佳实践
暂停程序,直到 powershell 脚本完成
如何使用 Python 中的参数运行 PowerShell 脚本
win2008如何在用bat调出的powershell窗口里运行命令