我很难理解为什么下面的脚本一旦到达第二个ForEach/IF语句就失败了。
有人能解释一下为什么这不管用吗?以及我将如何使用多个独立的If语句,并在同一个脚本中包含一个动作?
#Get the SharePoint list contents
$listItems= (Get-PnPListItem -List $ListName -Fields "Title","InquestTwoDate", "InquestThreeDate" -PageSize 1000)
#Iterate through each item in the List and set date to null
ForEach ($listItem in $listItems)
{
If($listItem[“InquestTwoDate”] -eq "$date")
{
Set-PnPListItem -List $ListName -Identity $listItem -Values @{“InquestTwoDate”=$null}
#Write-Host $listItem[“InquestTwoDate”]
}
}
#Iterate through each item in the List and set date to null
ForEach ($listItem in $listItems)
{
If($listItem[“InquestThreeDate”] -eq "$date")
{
Set-PnPListItem -List $ListName -Identity $listItem -Values @{“InquestThreeDate”=$null}
#Write-Host $listItem[“InquestThreeDate”]
}
}Error:
At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:23 char:14
If($listItem[“InquestTwoDateâ€
~
Array index expression is missing or not valid.
At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:23 char:14
If($listItem[“InquestTwoDateâ€
~~~~~~~~~~~~~~~~~~~~~Unexpected token '“InquestTwoDateâ€At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:23 char:14
If($listItem[“InquestTwoDateâ€
~~~~~~~~~~~~~~~~~~~~~
Missing closing ')' after expression in 'If' statement.
At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:22 char:1
{
~
Missing closing '}' in statement block or type definition.
At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:23 char:47
If($listItem[“InquestTwoDateâ€
~Unexpected token ')' in expression or statement.
At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:25 char:76
... t-PnPListItem -List $ListName -Identity $listItem -Values @{“Inques ...
~
Missing '=' operator after key in hash literal.At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:32 char:14
If($listItem[“InquestThreeDateâ€
~
Array index expression is missing or not valid.At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:32 char:14If($listItem[“InquestThreeDateâ€
~~~~~~~~~~~~~~~~~~~~~~~Unexpected token '“InquestThreeDateâ€At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:32 char:14If($listItem[“InquestThreeDateâ€
~~~~~~~~~~~~~~~~~~~~~~~
Missing closing ')' after expression in 'If' statement.
At C:\Users\%user%\Documents\PowerShell\Upload SharePoint items from CSV\deletedatefields2.ps1:31 char:1
{
~
Missing closing '}' in statement block or type definition.
Not all parse errors were reported. Correct the reported errors and try again.
CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : MissingArrayIndexExpressionhttps://stackoverflow.com/questions/69757507
复制相似问题