Кто последний изменял документ (Sharepoint) с помощью запроса Powershell - PullRequest
0 голосов
/ 21 апреля 2020

Мне нужно распечатать отчет, который показывает, кто редактировал документы, ниже приведен код, который я использую. Выходные результаты для:

'Modified by Option 1' is Microsoft.SharePoint.Client.User
'Modified by Option 2' is Microsoft.SharePoint.Client.FieldUserValue
What am I missing?
    #Get the web & Library
        $Web=$Ctx.Web
        $Ctx.Load($Web)
        $List = $Web.Lists.GetByTitle($LibraryName)
        $Ctx.ExecuteQuery()

        #Get All Files of from the document library - Excluding Folders
        $Query =  New-Object Microsoft.SharePoint.Client.CamlQuery
        $Query.ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq></Where><OrderBy><FieldRef Name='ID' /></OrderBy></Query></View>"
        $ListItems=$List.GetItems($Query)
        $Ctx.Load($ListItems)
        $Ctx.ExecuteQuery()

        $VersionHistoryData = @()
        #Iterate throgh each version of file
        Foreach ($Item in $ListItems)
        {
            $File = $Web.GetFileByServerRelativeUrl($Item["FileRef"])
            $Ctx.Load($File)
            $Ctx.Load($File.ListItemAllFields)
            $Ctx.Load($File.Versions)

            $Ctx.ExecuteQuery()


                #Send Data to object array
                $VersionHistoryData += New-Object PSObject -Property @{
                'daysSinceModified' =$daysSinceModified
                'File Name' = $File.Name
                'URL' = $FileURL
                'Modified by Option 1' = $File.ModifiedBy
                'Modified by Option 2' = $Item["Editor"]
                }
            }
        }

    }

Ответы [ 2 ]

0 голосов
/ 22 апреля 2020

used 'Modified by' = $ Item ["Editor"]. LookupValue

, которые возвращают короткое имя пользователя, например: John Smith

0 голосов
/ 22 апреля 2020

Вы можете попробовать использовать:

'Modified by Option 2' = $Item["Editor"].LookupValue
'Modified by Option 1' = $File.ModifiedBy.get_Title()

Результат теста: enter image description here

...