简体   繁体   中英

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.

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:

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..

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?

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

You haven't specified the Identity parameter (the item id). ie.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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