SPO Document UniqueID返回值为null

时间:2017-09-21 16:35:23

标签: powershell sharepoint-online

我正在使用SharePointPnP模块 我试图从位于一个列表下的每个文档中提取一些属性信息 我目前面临的一个问题是第29行的属性 $ Item.UniqueID 它抛出一个异常,因为UniqueID的返回值是$ null 但是,当我进入我的脚本并在Powershell控制台 $ Item 中运行以下命令时,我会获得密钥及其值的属性列表,包括UniqueID !!!

我的问题是,为什么我在每个项目中迭代时获得$ null值?

这是我的powershell脚本:

try
{
    Connect-PnPOnline -Url 'https://SomeCompany.sharepoint.com/FOA/BD/' -Credentials O365

    $Items = Get-PnPListItem -List 'Budget' | Where-Object{$_.FileSystemObjectType -eq 'File'}
    $ItemsFieldValues = $Items.FieldValues | Where-Object {$_.FileDirRef -like '*Models' -and $_.Title -like '*.xlsx' -and $_.Title -like '*-*'}
    $dtItems = New-Object System.Data.DataTable
    $dtItems.Columns.Add("ID", "Int64") | Out-Null
    $dtItems.Columns.Add("OperatingUnit","String") | Out-Null
    $dtItems.Columns.Add("HotelName","String") | Out-Null
    $dtItems.Columns.Add("Title", "String") | Out-Null
    $dtItems.Columns.Add("FileLeafRef", "String") | Out-Null
    $dtItems.Columns.Add("FileDirRef", "String") | Out-Null
    $dtItems.Columns.Add("UniqueID", "Guid") | Out-Null
    $dtItems.Columns.Add("ModifiedBy", "String") | Out-Null
    $dtItems.Columns.Add("ModifiedOn", "String") | Out-Null
    $dtItems.PrimaryKey =$dtItems.Columns[0]

    ForEach($Item in $ItemsFieldValues)
    {
        $TimeStamp = Get-Date -Format s
        $NewRow = $dtItems.NewRow()
        $NewRow.ID = $Item.ID
        $NewRow.OperatingUnit = $Item.Title.Split('-')[0]
        $NewRow.HotelName = ($Item.Title.Split('-')[1]).Split('.')[0]
        $NewRow.Title = $Item.Title
        $NewRow.FileLeafRef = $Item.FileLeafRef
        $NewRow.FileDirRef = $Item.FileDirRef
        $NewRow.UniqueID = $Item.UniqueID #$Item.UniqueID return value is $null
        $NewRow.ModifiedBy = $Global:CurrentUserName
        $NewRow.ModifiedOn = $TimeStamp
        $dtItems.Rows.Add($NewRow)
    }

    if($dtItems.Rows.Count -gt 0)
    {
        $SQLConnection.Open()
        $BulkCopy = New-Object("Data.SqlClient.SqlBulkCopy") $SQLConnection
        $BulkCopy.DestinationTableName = "[Models].[HotelsModels]"
        $BulkCopy.WriteToServer($dtItems)
    }
}

catch
{
    $ErrorLog = "Error On " + (Get-Date) + ";$($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)"
    Write-Error "$($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)"
    $NewRow = $Global:dtErrorLog.NewRow()
    $NewRow.TimeStamp = [System.datetime]::Now
    $NewRow.ErrorLog = $ErrorLog
    $Global:dtErrorLog.Rows.Add($NewRow)
    Save-ErrorLog
}
Finally
{
    $SQLConnection.close()
}        

谢谢

1 个答案:

答案 0 :(得分:0)

UniqueID 必须是区分大小写的 这是正确的脚本

 $NewRow.UniqueID = $Item.UniqueId 

由于

相关问题