Forum Discussion
Mats Warnolf
Feb 06, 2017Brass Contributor
Get all OneDrive for Business folders recursively
I have a litte problem. I'm migrating OneDrives between Office 365 tenants. In the receiving end they require that all documents have a major version. In the orginating end there are a few users that...
Feb 07, 2017
Use "Find-PnPFile" instead of Get-PnPFolderItem and try.
Function checkin-allfiles {
[cmdletbinding()]
param (
[Parameter (position = 0,HelpMessage = 'The Folder Site Relative URL (/Documents)', Mandatory = $TRUE)]
[String]$FSRU
)
$files = Find-PnPFile -Folder $FSRU -Match *
foreach ($file in $files) {
Set-PnPFileCheckedOut -Url $file.ServerRelativeUrl -Verbose
Set-PnPFileCheckedIn -Url $file.ServerRelativeUrl -CheckinType MajorCheckIn -Comment 'Checked In with Script to raise version to major' -Verbose
}
}Mats Warnolf
Feb 07, 2017Brass Contributor
Thanks.
Here is my final function:
Function Checkin-Allfiles {
<#
.SYNOPSIS
This function checks performs a CheckOut/CheckIn on files in order to elevate the files to Major Version.
.DESCRIPTION
This function checks performs a CheckOut/CheckIn on files in order to elevate the files to Major Version.
It requires the Office Dev PnP module SharePointPnPPowerShellOnline to be loaded at runtime.
.PARAMETER LibraryUrl
Specifies url of the site collection
.PARAMETER Folder
Specifies the Root Folder to check in files from
.EXAMPLE
Checkin-Allfiles -LibraryUrl https://contoso.sharepoint.com -Folder Documents
This gets all files in the documents folder and all subfolders, and checks in a new major version of all files
.EXAMPLE
Checkin-Allfiles -LibraryUrl https://contoso.sharepoint.com -Folder Documents/subfolder
This This gets all files in the Subfolder folder and all subfolders, and checks in a new major version of all files
#>
[cmdletbinding()]
param (
[Parameter (position = 0,HelpMessage = 'The Document Library URL', Mandatory = $TRUE)]
[String]$LibraryUrl,
[Parameter (position = 1,HelpMessage = 'The Folder Site Relative URL (Documents)', Mandatory = $TRUE)]
[String]$Folder
)
Write-Verbose -Message "Connecting to $LibraryUrl"
Connect-PnPOnline -Credentials (get-credential) -url $LibraryUrl
Write-Verbose -Message "Getting the files in $Folder"
$files = Find-PnPFile -Folder $Folder -Match * -Verbose
Write-Verbose -Message 'Done getting files'
foreach ($file in $files) {
Write-Verbose -Message "Checking out $($file.ServerRelativeUrl)"
Set-PnPFileCheckedOut -Url $file.ServerRelativeUrl
Write-Verbose -Message "Checking in $($file.ServerRelativeUrl)"
Set-PnPFileCheckedIn -Url $file.ServerRelativeUrl -CheckinType MajorCheckIn -Comment 'Checked In with Script to raise version to major'
}
}