I need to compare a file in SharePoint against a local file and to make sure they are the same version (it's an accdb that's developed offline and shared in multiple client SharePoint locations). I need to get the modified date from the file in SharePoint, and I've been unable to do so.
NB: I don't have Get-SPWeb available, as this needs to be run by various users who won't have SharePoint 2013 Management Shell available to them (reference).
I've tried using Get-PnPFile with -AsListItem, and it doesn't return an error but I can't access any properties.
I've tried .FieldValuesAsText and .ListItemAllFields and not getting anywhere.
This bit, connecting to the SharePoint resource via SharePointPnPPowerShellOnline, is working:
$SiteURL = "https://myorg.sharepoint.com/sites/mysite"
$FileRelativeURL = "Shared Documents/mydb.accdb"
$UserName = "user@myorg.org"
$PlainPassword = "myP@ssw0rd#"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
I tried this, and it downloads the file; I don't need to do that:
$file1 = Get-PnPFile -Url $FileRelativeURL -AsFile
According to this, "-AsListItem" returns the file as a listitem showing all its properties. So I tried it. It didn't download the file, and it didn't return an error, so maybe I have an object I can query now?
$file1 = Get-PnPFile -Url $FileRelativeURL -AsListItem
write-host $file1
The second line returns Microsoft.SharePoint.Client.ListItem
.
The following return empty strings:
write-host $file1.Name
write-host $file1.TimeLastModified
write-host $file1.LastModified
write-host $file1[-1]
write-host $file1[0,1,2,3,4,5,6,7,8,9]
Found FieldValuesAsText mentioned somewhere, so I tried it:
$props = $file1.FieldValuesAsText
write-host $props
write-host $props[0]
The first one returns Microsoft.SharePoint.Client.FieldStringValues
; the second one returns an empty string.
Tried ListItemAllFields:
$props = $file1.ListItemAllFields
write-host $props
write-host $props[0]
The first line didn't generate an error; the second line returned an empty string; the third line returned:
Cannot index into a null array.
At line:1 char:1
+ write-host $props[0]
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Very new to PowerShell, and I'm probably missing something obvious. (SharePointPnPPowerShellOnline is installed and working.)
The code above doesn't include getting information from my local file; I haven't gotten that far yet. I imagine the instructions here will work. My issue is getting the metadata from the file in SharePoint.
Grateful for any assistance or pointing me to the right resource; I've done a couple hours of research and am coming up empty.