简体   繁体   English

PnP powershell 更改共享点列表项

[英]PnP powershell change sharepoint list items

I want to update a number of items on a sharepoint list.我想更新共享点列表中的一些项目。 The list has a field called servers and the servers are equal to a list of servers kept in an .txt file.该列表有一个名为 servers 的字段,这些服务器等于保存在 .txt 文件中的服务器列表。

In short I want to update the farm field to prod for all servers that are in the file (Server field on the list).简而言之,我想更新农场字段以生产文件中的所有服务器(列表中的服务器字段)。

The method would be to use Set-PnPListItem, but in combination with:该方法是使用 Set-PnPListItem,但要结合:

foreach($line in Get-Content $pathRead)

I can't get it to work.我无法让它工作。

I tried using -Identity $_.Server -Values @{"Farm" = "PROD"} but it returns: Set-PnPListItem : Cannot bind argument to parameter 'Identity' because it is null..我尝试使用 -Identity $_.Server -Values @{"Farm" = "PROD"} 但它返回: Set-PnPListItem : Cannot bind argument to parameter 'Identity' 因为它是空的..

Is there a way to update the list this way?有没有办法以这种方式更新列表?

Edit: Bigger script sample编辑:更大的脚本示例

$pathRead = "D:\CertScipts\Servrar_Prod.txt"
Import-Module "C:\PNP\SharePointPnPPowerShell2019\3.6.1902.2\SharePointPnPPowerShell2019.psd1"
if ($cred -eq $null)
{ 
$cred = Get-Credential
}
Connect-PnPOnline "-" -Credentials $cred
$list = Get-PnPList "Certifikat Auto"

foreach($line in Get-Content $pathRead) 
{  
Set-PnPListItem -List $list -Identity -Values @{"Farm" = "PROD"}
}

Edit2 Can I use a camel-query, Get-PnPListitem -list $list -Query that uses $line to just list the items that have a server from my .txt file? Edit2 我可以使用骆驼查询,Get-PnPListitem -list $list -Query 使用 $line 来列出我的 .txt 文件中具有服务器的项目吗?

Set-PnPListItem -List $list -Identity -Values @{"Farm" = "PROD"}

You haven't specified the Identity parameter (the item id).您尚未指定 Identity 参数(项目 ID)。 ie. IE。

Set-PnPListItem -List $list -Identity 1 -Values @{"Farm" = "PROD"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM