简体   繁体   English

PnP PowerShell 更新列表项

[英]PnP PowerShell Updating List Item

Please may someone help with the below error?请有人帮助解决以下错误? I'm trying to set a SharePoint yes/no field when another person field is not blank.当另一个人字段不为空时,我正在尝试设置 SharePoint 是/否字段。 For some reason the Set-PnPListItem cmdlet isn't accepting the $Item.Id identity within the ForEach loop:出于某种原因,Set-PnPListItem cmdlet 不接受 ForEach 循环中的 $Item.Id 标识:

#Parameters
$SiteUrl = "https://domain.sharepoint.com/sites/site"
$ListName = "list"
$ListGUID = "5527e75b-40c1-4a89-90a7-035e06f56457"

#Connect to site
Connect-PnPOnline $SiteUrl -Interactive

#Get the List contents
$ListData = (Get-PnPListItem -List $ListName -Id *).FieldValues

#Iterate through each Row in the CSV and import data to SharePoint Online List
ForEach ($Item in $ListData)
{
    Write-Host "Checking Item $Item"
    
    $C2T = $False
    If($null -ne $($Item."tst_x002f_pg"))
    {
    $C2T = $True
    }
    
    Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst_x002f_yn" = "$C2T"}

}

And here are the errors:以下是错误:

Get-PnPListItem : Cannot bind parameter 'Id'. Cannot convert value "*" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:10 char:50
+ $ListData = (Get-PnPListItem -List $ListName -Id *).FieldValues
+                                                  ~
    + CategoryInfo          : InvalidArgument: (:) [Get-PnPListItem], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,PnP.PowerShell.Commands.Lists.GetListItem
 
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem
Checking Item System.Collections.Generic.Dictionary`2[System.String,System.Object]
Set-PnPListItem : No -Identity has been provided specifying the item to update
At C:\Users\%USERNAME%\Documents\PowerShell\UpdateFieldBasedonAnotherField.ps1:23 char:5
+     Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tst ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Set-PnPListItem], PSArgumentException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.SetListItem

PS C:\Windows\system32> 

I'd appreciate any help anyone could give.我很感激任何人可以提供的任何帮助。

Many thanks,非常感谢,

Alex.亚历克斯。

Please run the below PowerShell script as an admin:请以管理员身份运行以下 PowerShell 脚本:

#Parameters
$SiteUrl = "https://domain.sharepoint.com/sites/echodu/"
$ListName = "{listname}"
$ListGUID = "d8b1c97a-7787-40ef-9a02-d25282a9135a"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

$ListData = Get-PnPListItem -List $ListName

ForEach ($Item in $ListData)
{  
    $C2T = $False
    if($Item["tstpg"]){ 
        $C2T = $True        
    }
    
    Write-Host "Checking Item: $($Item["Title"])"
    Write-Host "Id :" $Item["ID"]
    Set-PnPListItem -List $ListGUID -Identity $Item.Id -Values @{"tstyn" = $C2T}
    
}

Before:前:

在此处输入图片说明

After:后:

在此处输入图片说明

在此处输入图片说明

Note: Enter the Internal Displayname of columns Note:输入列的内部显示名称

在此处输入图片说明

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

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