【问题标题】:PnP PowerShell Updating List ItemPnP PowerShell 更新列表项
【发布时间】:2021-12-27 19:26:05
【问题描述】:

请有人帮忙解决以下错误?当另一个人字段不为空时,我正在尝试设置 SharePoint 是/否字段。由于某种原因,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"}

}

以下是错误:

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> 

如果有人可以提供任何帮助,我将不胜感激。

非常感谢,

亚历克斯。

【问题讨论】:

    标签: powershell sharepoint sharepoint-online


    【解决方案1】:

    请以管理员身份运行以下 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}
        
    }
    

    之前:

    之后:

    Note: 输入列的内部显示名称

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-02
      • 2021-05-05
      • 2021-12-12
      • 2021-04-24
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      相关资源
      最近更新 更多