none
Power Shell Script for SharePoint Online

    Question

  • Hi,

    I am using SharePoint online.I need a Power Shell Script for below scenario.

    I have a web Application===In that Web App I have many Sub sites.===In all Sub sites I have a Same Library===In all Library I have Same Folder Structure.=== At one Place in Folder Structure I want to Create a Report in which I can check That how many folders are Empty or How many folder have some files, Report should be for all sub sites within a Site Collection.

    Can anyone give me the script for above issues.

    Thanks

    Abhi

    Wednesday, April 19, 2017 3:36 PM

All replies

  • SharePoint Online does not have a concept of web applications, or at least not ones you can access using the SharePoint Online Management Shell.

    This forum isn't a place to request scripts, it's for troubleshooting technical issues. If you have a script that is not working we can help diagnose why.

    Have you tried writing a script yet?

    I recommend you take some time to learn about the SharePoint Online Management shell and its available cmdlets.

    From a high level it sounds like you will want to write a script that retrieves an SharePoint Online site collection (SPOSite object) and iterates through the content to report on the specific information you need.

    Wednesday, April 19, 2017 5:54 PM
  • Hi,

    I am using SharePoint online.I need a Power Shell Script for below scenario.

    I have a web Application===In that Web App I have many Sub sites.===In all Sub sites I have a Same Library===In all Library I have Same Folder Structure.=== At one Place in Folder Structure I want to Create a Report in which I can check That how many folders are Empty or How many folder have some files, Report should be for all sub sites within a Site Collection.

    Can anyone give me the script for above issues.

    Thanks

    Abhi

    Wednesday, April 19, 2017 6:04 PM
  • Hi

    try this code, and let me know if you need more details

    Add-Type -Path "path\Microsoft.SharePoint.Client.dll" 
    Add-Type -Path "path\Microsoft.SharePoint.Client.Runtime.dll" 
    $SiteCollectionUrl = Read-Host -Prompt "Enter site collection URL: ";
    $list_name = Read-Host -Prompt "Provide library's name ";
    
    $global:cred = Get-Credential
    Connect-MsolService -Credential $global:cred -ErrorAction SilentlyContinue
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollectionUrl)
    $cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.username, $cred.Password)  
    $ctx.Credentials = $cred
    
    $rootWeb = $ctx.Web
    $childWebs = $rootWeb.Webs
    $ctx.Load($childWebs)
    $ctx.ExecuteQuery()
    
    foreach ($childWeb in $childWebs)
    {
    $mylist = $childWeb.Lists.GetByTitle($library_name)
    $ctx.Load($mylist)
    $ctx.ExecuteQuery()
     
    $camllibrary= "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType'/><Value Type='Integer'>1</Value></Eq></Where></Query></View>"
    $cquerylibrary = New-Object Microsoft.SharePoint.Client.CamlQuery
    $cquerylibrary.ViewXml=$camllibrary  
    
    $folders = $mylist.GetItems($cquerylibrary)
    $ctx.Load($folders)
    $ctx.ExecuteQuery()
    
    foreach ($folder in $folders)
    {
        $files = $mylist.RootFolder.Folders.GetByUrl($folder.FieldValues['FileRef'].Split('/')[-1]).files
        $ctx.Load($files)
        $ctx.ExecuteQuery()
        "The folder "+ $folder.FieldValues['FileRef'] +" contains " +    $files.Count + " files"
    }
    
    }


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.



    Wednesday, April 19, 2017 9:50 PM

  • Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Wednesday, April 19, 2017 10:00 PM
  • Hi,

    I tried your code but It gives a long Error. I am attaching the screenshot for your reference. Please let m know where is the problem?

    

     

    Thursday, April 20, 2017 4:22 AM
  • Hi

    yes, rightmy mistake :(

    Please replace

    $list_name = Read-Host -Prompt "Provide library's name ";

    with

    $library_name = Read-Host -Prompt "Provide library's name ";


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Thursday, April 20, 2017 8:00 AM
  • Hi,

    Thanks for Changes.

    Let me Tell my Questions Once more...

    I am using SharePoint online.I need a Power Shell Script for below scenario.

    I have a Site Collection===In that Site Collection I have many Sub sites.===In all Sub sites I have a Same Library===In all Library I have Same Folder Structure.=== In Folder Structure I want to Create a Report in which I can check That how many folders are Empty or How many folder have some files, Report should be for all sub sites within a Site Collection.

    For Example:--

    Hotels(Site Collection)===Hotel1(Subsite1)==Sales(Library)==Total Sales(Folder)==Month(Folder)==Day1,Day2,Day3,Day4.....(Many Folders)

                                               Hotel2(Subsite2)==Sales(Library)==Total Sales(Folder)==Month(Folder)Day1,Day2,Day3,Day4.....(Many Folders)

                                              Hotel3(Subsite3)==Sales(Library)==Total Sales(Folder)==Month(Folder)Day1,Day2,Day3,Day4.....(Many Folders)

    My Issue is, I need to check that Which folders(Day1,Day2,Day3,Day4) have files or Not because if there is no file I want to delete that folder(Day1,Day2,Day3,Day4).

    For that I need to create some type of report where I can Check all the Days folders with their Files or I can delete all the Blank Day Folder directly.

    Let me know If you have any question.

    Thanks for your Help...

    Thursday, April 20, 2017 11:20 AM
  • Hi

    please check my complete example, which search for empty folders in specific library

    http://romeodonca.com/deleting-empy-folders-in-sharepoint-online-using-powershell-csom/

    let me know if you need more details


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Sunday, April 23, 2017 12:10 PM
  • When I run your script. I am getting Below Error.

    Monday, April 24, 2017 5:27 PM