Forum Discussion
Nigel_Price9911
Feb 12, 2018Iron Contributor
How Do I get the version of a file using PnP Powershell
Hi
I am trying to get the version of a file in a document library using PnP Powershell.
Connect-PnPOnline -Url <url>
$ListItems = Get-PnPListItem -List <MyDocLibrary>
for each ($item...
Nigel_Price9911
Feb 14, 2018Iron Contributor
Works great (as long as you put the t on the end of Get-PnPContex !)
What about if I only want the latest version ?
Regards
Nigel
Dean_Gross
Feb 14, 2018Silver Contributor
Nigel_Price9911 something like the following should help you get started, I have not tested this.
for (int i = versions.Count; i > 0; i--)
{
FileVersion version = file.Versions[i - 1];
string label = version.VersionLabel;
string id = version.ID.ToString();
string filename = Path.GetFileName(version.Url);
string ext = Path.GetExtension(version.Url);
string tmp1 = version.IsCurrentVersion;
string tmp2 = version.Url;
}