Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-SPOFolderFiles
- $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
- $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
- $ctx.Load($ctx.Web)
- $ctx.ExecuteQuery()
- Write-Host "Logged into Sharepoint"
- $ll=$ctx.Web.Lists.GetByTitle( $ListTitle)
- $ctx.Load($ll)
- $ctx.ExecuteQuery()
- ## Page Position
- $page = $null
- ## All Items
- #$spqQuery.ViewXml="<View Scope='FilesOnly'><RowLimit>1000</RowLimit></View>"
- $qCommand = @"
- <OrderBy>
- <FieldRef Name='ID' Ascending='TRUE'/>
- </OrderBy>
- Do{
- $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
- $spqQuery.ListItemCollectionPosition = $page
- #$spqQuery.ViewAttributes = "Scope='Recursive'";
- #$spqQuery.RowLimit = 100
- #$spqQuery.Query = $caml
- $spqQuery.ViewXml = $qCommand
- $itemki=$ll.GetItems( $spqQuery)
- $ctx.Load($itemki)
- $ctx.ExecuteQuery()
- ## Getting the position of the previous page
- $page = $itemki.ListItemCollectionPosition
- Write-Host "################## PAGE " $page.PagingInfo " #########################"
- Write-Host "processing query results. Recs: " + $itemki.Count
- $Counter = 0;
- foreach($item in $itemki)
- {
- $Counter++
- Write-Host $Counter - $item["FileRef"] $item.ElementType
- $file = $ctx.Web.GetFileByServerRelativeUrl($item["FileRef"]);
- $ctx.Load($file)
- $ctx.Load($file.Versions)
- $ctx.Load($file.ListItemAllFields)
- $Author=$file.Author
- $CheckedOutByUser=$file.CheckedOutByUser
- $LockedByUser=$file.LockedByUser
- $ModifiedBy=$file.ModifiedBy
- $ctx.Load($Author)
- $ctx.Load($CheckedOutByUser)
- $ctx.Load($LockedByUser)
- $ctx.Load($ModifiedBy)
- #$ctx.Load($file.EffectiveInformationRightsManagementSettings)
- #$ctx.Load($file.Properties)
- #$ctx.Load($file.VersionEvents)
- try
- {
- $ctx.ExecuteQuery()
- }
- catch
- {}
- if($CheckedOutByUser.LoginName -ne $null){
- Write-Host "File Name" $file.Name
- Write-Host "Checked out by" $CheckedOutByUser.LoginName
- $file.CheckIn('Checked in automatically', 'MajorCheckIn')
- $ctx.Load($file)
- try
- {
- $ctx.ExecuteQuery()
- Write-Host $file.Name " has been checked in" -ForegroundColor DarkGreen
- }
- catch [Net.WebException]
- {
- Write-Host $_.Exception.ToString()
- }
- }
- }
- }
- Until($page -eq $null)
- #Add required references to SharePoint client assembly to use CSOM
- #Enter the data
- $spPassword ="a password that is super duper secure"
- $secureStringPwd = ConvertTo-SecureString -string $spPassword –asplaintext –force
- #$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
- $username="userUserton@aCompany.onmicrosoft.com"
- $Url="https://aCompany.sharepoint.com/DocManage/PDFRepo/"
- #$Url="https://aCompany.sharepoint.com/DocManage/TiffRepo/"
- $ListTitle="Documents"
Add Comment
Please, Sign In to add comment