powershell - 使用 CSV 中的 PowerShell 更新 Sharepoint 在线列表
问题描述
我是一个powershell初学者,我遇到了一个问题。我需要更新在线共享点上的列表,其中数据来自通过 powershell 的 CSV 文件。如果该项目存在于列表中,则脚本只会在有任何差异时更新。如果该项目不存在,脚本将添加该项目我找到了一个基本上可以满足我需要的脚本,但是对于sharepoint服务器。有人可以帮我在线转换为sharepoint吗?谢谢你
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Read the CSV file
$CSVData = Import-CSV -path "C:\UserData.csv"
#Get the Web
$web = Get-SPWeb -identity "http://portal.crescent.com"
#Get the Target List
$List = $web.Lists["ExpertProfiles"]
#Iterate through each Row in the CSV
foreach ($Row in $CSVData)
{
#Filter using CAML Query
$CAMLQuery="<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>$($Row.Name)</Value></Eq></Where>"
$SPQuery=New-Object Microsoft.SharePoint.SPQuery
$SPQuery.ViewAttributes = "Scope='Recursive'" #Get all items including Items in Sub-Folders!
$SPQuery.Query=$CAMLQuery
$SPQuery.RowLimit = 1
#Get the List item based on Filter
$Item=$List.GetItems($SPQuery)[0]
If($Item -ne $null)
{
#Update List Item
$Item["Department"] = $Row.Department
#$item.Update()
Write-Host "Updated:"$row.Name -ForegroundColor Green
}
else
{
write-host "No matching Item Found for:"$row.Name -f Red
}
}
解决方案
推荐阅读
- c# - 将对象移动到其面对的方向给定的距离c#
- python-sphinx - 从标签和参考自动生成索引
- php - 如何在 WooCommerce 管理订单列表中的新列中添加“Local Pickup Plus 取货日期”
- docker - Drone - 使用drone.yml 使用自定义日期时间字符串格式命名 docker 图像标签
- java - Serenity 测试未使用 Serenity Parameterized Runner 运行
- java - 启动/停止服务后 Activity 中的本机崩溃
- excel - 传递给 Excel 的用于过滤的日期变量未正确激活
- viewer - 伪造查看器 isLayerVisible 始终为 false
- python - 在 jupyter 笔记本单元格上加载 markdown 文件
- symfony - Symfony 4 cookie、SameSite 和 firefox/chrome 警报