I’ve often had times, where I’ve migrated a whole load of documents from a File Server or some other ECMS. These exported documents are normally in major published state and need to be in the same state in SharePoint (i.e. Published!).

Sweet and simple, but very effective.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$sites = "https://contoso.sharepoint.com/sites/site1", "https://contoso.sharepoint.com/sites/site1"

foreach ($site in $sites)
{
Connect-PnPOnline -Url $site -UseWebLogin

$list = Get-PnPList -Identity "Documents"

$items = (Get-PnPListItem -List $list -Fields "Title","GUID","FileRef").FieldValues

foreach ($item in $items)
{
$file = $item.FileRef

Set-PnPFileCheckedIn -Url $file -CheckinType MajorCheckIn -Approve
}
}