Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cls
- function Recurse ($folder){
- write-host ----- $folder.Name
- $context.Load($folder.Subfolders)
- $context.ExecuteQuery()
- foreach($folder in $folder.Subfolders)
- {
- write-host ---------- $folder.Name
- }
- # write-host -------------- $folder.Subfolders
- }
- function GetChildFolders($RootFolder)
- {
- $context.Load($RootFolder)
- $context.Load($RootFolder.Folders)
- $context.ExecuteQuery()
- write-host $RootFolder.Name
- foreach($folder in $RootFolder.Folders)
- {
- if($folder.Name -ne "Forms")
- {
- Recurse -folder $folder
- }
- }
- }
- function Get-SPOWebs(){
- param(
- $Url = $(throw "Please provide a Site Collection Url"),
- $Credential = $(throw "Please provide a Credentials")
- )
- $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
- $context.Credentials = $Credential
- $web = $context.Web
- $context.Load($web)
- $context.Load($web.Webs)
- $context.ExecuteQuery()
- foreach($web in $web.Webs)
- {
- Write-Host ""
- Write-Host ""
- Write-Host ------------- $web.Title -------------
- $lists = $web.lists
- $context.Load($lists)
- $context.ExecuteQuery()
- foreach ($list in $lists)
- {
- if($list.BaseType -eq "DocumentLibrary") {
- $list.RootFolder
- GetChildFolders -RootFolder $list.RootFolder
- }
- }
- Get-SPOWebs -Url $web.Url -Credential $Credential
- $web
- }
- }
- $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
- $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
- $UserName = "User"
- $Password = "Pass"
- $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
- $SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
- $AllWebs = Get-SPOWebs -Url 'sharepointSiteURL'-Credential $SPOCredentials
- function global:RecurseFolders([Microsoft.SharePoint.Client.Folder] $folderObject, $Context = $null, $tab = "")
- {
- if ($Context -eq $null)
- {
- Throw "The Context was Null and you MUST have a context to continue."
- }
- $Context.load($folderObject.folders)
- $Context.ExecuteQuery()
- write-host($tab+$folder.Name)
- $indent=" "
- $tab +=$indent
- foreach($folder in $folderObject.folders)
- {
- $Context.load($folder.files)
- $Context.ExecuteQuery()
- foreach ($file in $folder.files)
- {
- write-host($tab+"-F-"+$file.Name)
- }
- RecurseFolders -folderObject $folder -Context $Context -Tab $tab
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement