0

I need to print a report that shows who has edited documents, below is the code I am using. The output results for :

'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"]
                }
            }
        }

    }

Theo
  • 57,719
  • 8
  • 24
  • 41
Heidi
  • 45
  • 2
  • 9
  • Have a look at [this answer](https://stackoverflow.com/a/33527578/9898643). Looks like you need something like `$modified = $item.Fields.GetField("Editor"); 'Modified by Option 2' = $modified.GetFieldValue($item["Editor"])` – Theo Apr 21 '20 at 10:04

2 Answers2

0

You could try to use:

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

Test result: enter image description here

Amos
  • 2,030
  • 1
  • 5
  • 9
0

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

Which return the Users short name eg: John Smith

Heidi
  • 45
  • 2
  • 9