首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell多个IF语句和ForEach循环

问PowerShell多个IF语句和ForEach循环
EN

Stack Overflow用户
提问于 2021-10-28 16:09:18
回答 1查看 111关注 0票数 0

我很难理解为什么下面的脚本一旦到达第二个ForEach/IF语句就失败了。

多重ForEach/IF

有人能解释一下为什么这不管用吗?以及我将如何使用多个独立的If语句,并在同一个脚本中包含一个动作?

代码语言:javascript
复制
#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”]
    }
    }
代码语言:javascript
复制
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 : MissingArrayIndexExpression
EN

回答 1

Stack Overflow用户

发布于 2022-01-22 23:15:58

来自马斯兹's 评论

您应该使用常规双引号来代替:["InquestTwoDate"]

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69757507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档