首页 > 解决方案 > PnP PowerShell 代码语法错误问题

问题描述

我有一个函数可以遍历文档库并创建一个列出与每个项目关联的元数据的报告。

它不会编译。在第一个括号的函数声明中,我收到一个错误:

Missing closing '}' in statement block or type definition

我已经确定了似乎是错误来源的代码行。当我在 # 之间的行上剪切代码时,错误就消失了。

我无法弄清楚语法不正确的地方。我在用着:

SharePointPnPPowerShell2013 3.11.1907.0

function PopulateData($web, $incldeFileSize) {
        Write-Host "Current Site " $web.url -ForegroundColor Cyan 
                  $libs = Get-PnPList -Web $web | Where{($_.BaseType -eq “DocumentLibrary”) -or ($_.Title -eq "Pages") }

                  foreach($lib in $libs){
                     $libitems = (Get-PnPListItem -Web $web -List $lib -Fields "FileLeafRef","Name","Title","Author","Modified","Created","KBAbstract","KBContentAuthor","KBCategory","Publish","KBPublishDate").FieldValues

                       foreach($libitem in $libitems)
                         {
                             if($libitem.FSObjType -eq "0"){
                              $data = @{
                                          "Web Name" = $web.Title
                                          "Library Name" = $lib.Title
                                          "File Name" = $libitem.FileLeafRef
                                          "Abstract" = $libitem.KBAbstract
                                          "Content Author" = $libitem.KBContentAuthor.Email

                                          ############The Problem is somewhere in these Lines of code###########
                                          [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValueCollection]$MMSFieldValueColl = $libitem.KBCategory
                                            $MMSFieldTerms = ""
                                            Foreach($MMSFieldValue in $MMSFieldValueColl)
                                            {
                                                if($MMSFieldValue.label -ne $null)
                                                {
                                                    $MMSFieldTerms+=$MMSFieldValue.label+"; "
                                                }
                                            }
                                            write-host $MMSFieldTerms
                                            ##########The Problem ends here############

                                          "Knowledge Area" = $libitem.KBCategory
                                          "Publish" = $libitem.Publish
                                          "Published Date" = $libitem.KBPublishedDate.LookupValue
                                          "File URL" = $libitem.FileRef
                                          "Modified Date" = $libitem.Modified
                                          "Created By" = $libitem.Author.LookupValue
                                          "Created Date" = $libitem.Created
                                          "Modified By" = $libitem.Editor.LookupValue
                                          "File Size (KB)" = $null
                                     }
                             if($incldeFileSize -eq $true){
                                    $file = Get-PnPFile -Url $libitem.FileRef
                                    $data["File Size (KB)"] = $file.Length / 1KB
                              }
                              New-Object PSObject -Property $data
                            }
                         }
                  }       
}

标签: powershell

解决方案



推荐阅读