Powershell script to count number of list and library items in site collection

We are identifying large lists in our 2010 SP environment and I'm attempting to write code to output the total number of list items in a site collection.   I'm using the code below but it only displays column data for title and url. 
What do I need to add so it can count the number of items in each sharepoint list and library? 
Get-SPSite -WebApplication http://sharepoint -Limit All |
   Select -ExpandProperty AllWebs |
   Select -ExpandProperty Lists |
   Select ParentWebUrl, Title
I'm referencing
http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts

Please find belwo script, it will iterarte through all the folder/Subfoder to get the item counts from all list and library, you can modify this script to run this at site collection scope:
Note: save the script in .ps1 file and execute the script as described below to get log file, it will save the log file out.txt in seleted directory:
e.g.PS D:\PowershellScripts> .\ListItemCount.ps1 > out.txt
$SPWebApp = Get-SPWebApplication "http://weburl.com/"
foreach ($SPSite in $SPWebApp.Sites)
if ($SPSite -ne $null)
foreach ($SPWeb in $SPSite.AllWebs)
foreach ($list in $SPWeb.Lists)
$ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
Write-Output $ListURL
[Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
#$query.Folder = fldr;
#Recursive Scope....
$query.ViewAttributes = "Scope='Recursive'"
$allitems = $list.GetItems($query);
$filecount = $allitems.Count;
Write-Output " No of item: " $filecount
if ($SPWeb -ne $null)
$SPWeb.Dispose()
if ($SPSite -ne $null)
$SPSite.Dispose()
You can update the code to get any specific list type item count, using if($list.BaseType -eq "DocumentLibrary") condition:
if($list.BaseType -eq "DocumentLibrary")
$ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
Write-Output $ListURL
[Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
#$query.Folder = fldr;
#Recursive Scope....
$query.ViewAttributes = "Scope='Recursive'"
$allitems = $list.GetItems($query);
$filecount = $allitems.Count;
Write-Output " No of item: " $filecount
if ($SPWeb -ne $null)
$SPWeb.Dispose()
If my contribution helps you, please click Mark As Answer on that post and Vote as Helpful
Thanks, ShankarSingh

Similar Messages

  • Powershell script to find number of major and minor version for a item

    Is there a way to figure out to get the total major and minor version count for an item in powershell.
    I can get the count on basis of following
    “Item Versions” = $item.Versions.Count
    but not sure how to get number of major and number of minor version for an item. Pls advice.
    Thanks Basva

    Hi Basva,
    There might be an easier way, but this should work:
    foreach($item in $list.Items)
    $minor = 0
    $major = 0
    foreach($version in $item.Versions)
    if($version.Level -eq "Draft")
    $minor += 1
    else #Assume Level must be Published
    $major += 1
    #The variables $minor and $major will now hold
    #the correct number of versions for this item

  • Getting Error while creating a new column in a list or library in a site collection - Sharepoint 2013

    Hi,
    I am getting below error when i create a new column in a library or list,
    "Save Conflict
    Your changes conflict with those made concurrently by  another user. IF you want your changes to be applied, click back in your browser, refresh the page, and resubmit your changes"
    Any help please.
    Smile Always

    Hi,
    I have done a test in my SharePoint 2013. And I can re-appear your issue.
    Per my test, I found that If  there are more than one user create a new column in
    a library or list at the same time, when we
    click ok after the other users, we will get the error.
    Or if we open a library or list in two windows with the same user, when we
    create a new column in a library or list in two windows
    at the same time, we will get the error.
    To resolve your issue, refresh your page and
    create a new column again.
    Best Regards,
    Lisa Chen
    Lisa Chen
    TechNet Community Support

  • Users in a SharePoint list and Library using powershell

    Hi,
      How to get the number of users in a list or library of a site using powershell

    Hi spadminspadmin,
    You may try following script.
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    $WebUrl = Read-Host 'Please input URL address of target web'
    $Web = Get-SPWeb $WebUrl
    $ListName = Read-Host 'Please input list name'
    $List = $web.Lists[$ListName]
    $Unique = $List.hasuniqueroleassignments
    if (($List.permissions -ne $null) -and ($Unique -eq "True"))
    Write-Output "---------------------"
    Write-Output "List permission is: "
    $List.permissions | fl member, basepermissions
    elseif ($Unique -ne "True") {
    Write-Output "Inherits permissions from $Web"
    Write-Host "----------------------"
    $web.dispose()
    Thanks & Regards,
    Emir
    Emir Liu
    TechNet Community Support

  • PowerShell Script to Create a Contact Card and Enable Email Forwarding

    Exchange 2010
    Can anyone help with creating a powershell script to create a contact card and set email forwarding at the sametime?
    I'm looking to import a list of 200 users via a text or csv file, create the contact card with first name, middle initial if one exists, last name, (no alias) and put the contact card in the following OU "DIS###" in the a.b.c.com domain as well
    as enable forwarding to @mail.com.
    I've been able to create a script to enable mail forwarding but it doesn't help me without a contact card.  I hate to put this upon anyone, but my ps scripting and Exchange knowledge is still in it's infant stage and I need get this done post haste

    Q:Import csv: Does this contain 200 mailboxes name
    A:It contains 200 user logon names.
    For the mail forwarding:
    I currently have a csv file with two columns -- one named displayname and the next call mailaddress.  Under the displayname column I have the users account name (first.mi.last -- middle initial if they have one) and under mailaddress i have @mail.com.                                                                                                           
    script:                                                                                                                                                                    
    Import-CSV C:\setmailforwarding\mailforwarding.csv | foreach-Object{Get-Mailbox $_.displayname | set-Mailbox -forwardingAddress $_.mailaddress}
    The above script should work if the contact card has been created.  Obviously I need to create the card first.
    I don't have a script to set up the contact card as of yet -- I was hoping to get some help on that.
    Q:E-mail forwarding: Is this  from  mailboxes to mail contact, you will be creating
    A:Not really sure what you are asking.  I'm looking to create the contact card with a csv or txt file for first name, middle initial if one exists, last name, (no alias) and put the contact card in the following OU "DIS###" in the a.b.c.com domain as
    well as enable forwarding to @mail.com.  The users current email is @mail.1234.com and we will be migrating our mailboxes to another organization that uses @mail.com.  I will need to set forwarding in the interim until the migration is complete.
    Hope this helps.

  • Need help to count number of rows and display in file

    Hello,
    my scenario is IDOC to File......i am using XSLT mapping and using FCC parameters to convert the flat file.
    now new requirement is i need to count number of rows and add count value last of the file.
    Please let me know how to do it,
    thanks in advance for your help.
    Regards,
    Chinna

    thanks again, one more Q.
    in XSLT mapping i have written for loop for complete structure.
    example : <Details>
                         <node1>
                         <node2>
                   </details>
    in XSLT mapping
                         <xsl:for-each select="ZMATMAS_01/IDOC/E1MARAM">
         <Details>
         </Details>
         </xsl:for-each>
    if i add the field at target side....then i will come under details node and it will be repeated.
    how to declare in XSLT mapping.

  • Setup my site error message says: "You do no have permissions to have lists and pages within my site

    Hello Community
        In Sharepoint 2010 after entering the url to My Site in order to create my personal site
     the "My Content" link was clicked.
        Instead of going to another page a message gets display across the page stating:
    "You do not have permissions to have lists and pages within My Site."
        I am not logged on as the Farm account and I am not supposed to be.  I am just logged
    on as the domain user that created these web applications, services  and My Site.
        What kind of permissions do I need to have lists and pages within My Site?
        Thank you
        Shabeaut

    Hello Guru Karnik
        There has been no mention of "AAM" which I know understand is the abbreviation for:
    "Alternate Access Mapping."
        The "My site Host (url)" is the url of the
    :port/">http://<servername>:port/ that I created for the web application/site collection?
        And After that then will I have permissions to have lists and
    pages within My Site when I click "My Content"?
        If so, how do I create the AAM in SharePoint 2010?
        Thank you
        Shabeaut

  • How to show content of a list which resides in other site collection in Office 365?

    Hi All,
    Can anyone help on How to show content of a list which resides in other site collection in Office 365 . Using Rest and Soap services this is not possible as we have limitations in office 365.So if anyone have any idea please let me know.
    Note : We are not allowed to use CSOM for this requirement.
    Many Thanks,
    Vinod.

    Hi Vinod,
    You can use cross site publishing feature of SharePoint 2013.
    http://blogs.msdn.com/b/justinvoels/archive/2012/09/24/sharepoint-2013-search-driven-publishing-and-cross_2d00_site-collection-publishing-overview.aspx
    https://technet.microsoft.com/en-us/library/jj635883.aspx
    Alternative to cross-site publishing in SP Online
    https://www.youtube.com/watch?v=chwHhEmIERg
    Best Regards,
    Brij K
    http://bloggerbrij.blogspot.co.uk/

  • Can we set List View Lookup Threshold at site collection level ?

    Hello,
    Presently, we have requirement to set the List View Lookup Threshold  at Site Collection/Sub-Site level instead of web application level.
    Could you please let me know, are there any ways to set
    List View Lookup Threshold setting at Site Collection/Sub-Site level
    in SharePoint 2010 using Powershell/Object Model
    Also, it would be helpful if you colud let me know, upto what extent , we can drill down List View Lookup Threshold setting i.e. SubSite/List/Library-Folder.
    Thanks in advance !
    Regards,
    Sagar Acharya
    Email -  [email protected]

    Hi Sagar,
    We cannot set list view threshold value at sitecollection/subsite level. It can only be set at web application level.
    However we can bypass the 5000 limit using PowerShell command by setting “Enable Throttling”= false for particular list.
    Reference link:
    http://pravahaminfo.blogspot.in/2012/10/how-to-increase-list-view-threshold.html
    Thanks,
    Somnath Matere

  • How to make DW see Templates and Library items

    I imported a site from another computer. Now it cannot see templates as templates or library items as library items. I am downloading the files from the server. The templates folder is there, but they are not showing up in the assets panel. They are also not updating when I save them.
    How do I make DW see the templates and library items? It is a large site and I really don't want to have to recreate everything.

    I just had this problem and this is how I solved it:
    1. Create a brand new template (can be empty) and save it
    2. See where dreamweaver puts it in the files panel(more than likely will create a new template folder)
    3. Completely move all templates from your previous template folder to the new one DW just created.
    4. Voila - now check you templates under assets.
    Caution:
    1. First only copy one template to the new folder and check assets to test this theory before deleting the ones in the previous folder (if it works do be sure to delete the others)
    2. To tell if a template actually works, select it then hit delete, if it simply warns you this can't be undone the template is NO GOOD. If it gives you  a  list of links you will destroy THAT'S THE ONE YOU WANT TO KEEP.  The templates in the new folder should give you a list of links, any templates any where else will just give you a regular delete/warning message.
    Hope this solution works for you, I'm just trying to help.
    Michelle

  • Help to count number of words and time it

    Hi,
    I need help in inputting a text file using a file browser into a JTextArea and then count the number of occurance of each words in the file and display the time it takes in a JTextField.
    Right now I am able to come up with the idea of creating an Array to list all the words but I am still unable to count them. And by extending an abstract class to create the array class. Below is attached my abstract class.
    import java.io.*;
    import java.util.Observable;
    import java.util.StringTokenizer;
    public abstract class AbstractWordCounter extends Observable
         /** Amount of time required to count words in the most recently read file. */
         protected long readTime;
         /** DELIMETERS used in this WordCounter */
         protected String DELIMETERS;
         /** By default, any AbstractWordCounter will have is delimeters set to any non-letter ASCII character */
         public AbstractWordCounter()
              this.readTime = -1;
              DELIMETERS = "";
              // Add any non-letter ASCII character to the list of tokens.
              for(int i = 0; i < 256; i++)
                   if( !Character.isLetter( (char)i  ) )
                        DELIMETERS += Character.toString( (char)i);
         /** Get the delimeters used in this WordCounter */
         public String getDelimeters()
              return DELIMETERS;
         /** Change the delimeters used in this WordCounter
          * @param newDelimeters the new delimeters to be used
         public void setDelimeters(String newDelimeters)
              DELIMETERS = newDelimeters;
          *@return    The number of unique words in this WordCountItem object
         public abstract int getSize();
         /** @return  The total number of words counted by this WordCounter */
         public abstract int getTotalNumWords();
         /** Add a String to this WordCounter
          * @param s the String s is converted to lower-case.  If the lower-case String is already in the list, it's count is
          *        incremented.  Otherwise it is added to the list and its count is set to 1.
         public abstract void add(String s);
          * Get the ith WordCountItem
          *@param  i  must be between 0 and size - 1 (inclusive)
          *@return    The WordCountItem stored at the ith location
         public abstract WordCountItem getWordCountItem(int i);
          *  Clear this WordCounter.  After this method runs, this.size == 0.
         public abstract void clearCount();
         /** @return The amount of time (in milliseconds) that was required to read the most recent file */
         public long getReadTime()
              return this.readTime;
          *  Reads the file.  Converts each word in the file to lower case and adds it to this
          *  AbstractWordCounter.  The AbstractWordCounter is cleared before reading the new file.
          *  The time required to read the file and count the words is recorded.
          *@param  fileName  file to be opened.
          *@throws FileNotFoundException
         public final void readFile(String fileName) throws FileNotFoundException
              // Clear this AbstractWordCounter.  Open the file and count the words in the file.
    }Then the time I have come up so far is in the class that extends the abstract class above and the code is as:
    public long getReadTime()
              return this.readTime;
         }and I have a hard time to actually display this in a JTextField as it says non-static cannot be applied to a static content and if I change the method into static, another error of overiding the abstract occurs...
    I am totally lost for these errors. And I am still unable to create a file browser to find a file. For now I just write a complete path to open the file.
    would someone could point me the right direction for this problem... Thanks in advance

    Crosspost: http://forum.java.sun.com/thread.jsp?forum=31&thread=521763&tstart=0&trange=15

  • Looking for help with PowerShell script to delete folders in a Document Library

    I'd like to create a PowerShell script to delete old folders in a Document library that are over 30 days old. Has anyone created something like this?
    Orange County District Attorney

    Hello Sid:
    I am trying to do the same and Iam running the script to delete the subfolders inside a folder  but I have some errors. 
    Could you please take a look?
    _______Script________
    $web = Get-SPWeb -Identity https://myportal.mydomain.com
    $list = $web.GetList("ar_mailingactivity")
    $query =  New-Object Microsoft.SharePoint.SPQuery 
    $camlQuery = '<Where><And><Eq><FieldRef Name="ContentType" /><Value Type="Computed">Folder</Value></Eq><Leq><FieldRef Name="Created" /><Value Type="DateTime"><Today OffsetDays="-30" /></Value></Leq></And></Where>'
    $query.Query = $camlQuery
    $items = $list.GetItems($query)
    for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--)
       $items.Delete($intIndex);
    ________Errors_______
    Unable to index into an object of type System.Management.Automation.PSMethod.
    At C:\Script.ps1:2 char:22
    + $list =$webGetList <<<< "ar_mailingactivity"]
    + CategoryInfo
    :InvalidOperation: (ar_mailingactivity:String) [], RuntimeException
    + FullyQualifiedErrorID
    :CannotIndex
    You cannot call a method on  a null-valued expression.
    At c:\Script.ps1:6 char:24
    + $items = $list.GetItems <<<< ($query)
    + CategoryInfo
    :InvalidOperation: (GetItems:String) [], RuntimeException
    + FullyQualifiedErrorID
    :InvokeMethodOnNull

  • Calling Recursive function with Powershell to list all documents in the document library under a SIte collection

     function Recurse($RootFolder,$List) {
                            $Context.Load($RootFolder)
                            $Context.Load($RootFolder.Folders)
                            $Context.ExecuteQuery()
                            foreach($folder in $RootFolder.Folders)
                                if($Folder.Name -ne "Forms")
                                        $Context.Load($folder)
                                        $Context.Load($folder.Files)
                                        $Context.ExecuteQuery()
                                        foreach($file in $folder.Files)
                                            $FileCollection +=
    $file
                                        Recurse $folder $List 
                                Recurse $folder.ParentFolder $List
                                Return $FileCollection
    I am trying to traverse through SharePoint Online Site collection using Powershell CSOM. I am able to go to the last folder from the root folder which is 2-3 levels down. But I could not search through all the document libraries as it gets struck to one
    of the last document library.

    Below script is working for me. I can now traverse through all the folders and subfolders including the root folders to fetch all the files using Powershell and CSOM.
    #function begins
                        function Recurse($RootFolder) {
                            $Context.Load($RootFolder)
                            $Context.Load($RootFolder.Folders)
                            $Context.ExecuteQuery()
                            $Context.Load($RootFolder.Files)
                            $Context.ExecuteQuery()
                            $resultCollection = @()
                            foreach($file in $RootFolder.Files)
                                $resultCollection += $file
                            foreach($folder in $RootFolder.Folders)
                                if($Folder.Name -ne "Forms")
                                   Recurse $folder  
                                Return $resultCollection
                        # Function ends

  • PowerShell Command to export a list of subsites from a site collection

    Is there a Powershell command to export a list of sub sites from a site collection into a .csv file?
    Thanks.

    Hi,
    According to your post, my understanding is that export subsites to excel via PowerShell.
    There is an article about this topic, it will enumerate all the sub-sites and print them in a .csv file, you can refer to them.
    http://www.sharepointfix.com/2012/02/powershell-script-to-enumerate-sites.html
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • How can we retrieve list and library data from rest services

    Hi Everybody,
    How can we get the list or library data from sharepoint 2010 rest services.
    Here is the URL I am trying: https://siteurl/_vti_bin/listdata.svc
    Can anybody please provide sample c# code to pull the info.
    Thanks in advance,
    Krishna
    Krishnasandeep

    Here is reference material:
    http://msdn.microsoft.com/en-us/library/ff798339.aspx
    And an example:
    http://www.c-sharpcorner.com/uploadfile/anavijai/rest-api-in-sharepoint-2010-for-listdata-svc-part-2/
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

Maybe you are looking for

  • How can I manually change contrast/brightness/colors?

    I want to simply use some slider to adjust the contrast, brightness, gamma or color balance in my MacBook Pro, but for some reason I'm unable to find it. All I can find is the calibration process, but when I calibrate it "correctly", the screen is a

  • Endeca.Data.ConnectionException: Could not connect to Endeca Server/MDEX Engine. I am using MDEX 6.4.1. Getting a 404 Error.

    Hi, I am new to Endeca. We have an Endeca DEV server, MDEX 6.4.1. Forge is running fine. I am able to connect to the Orange App and getting the products. http://devmachine:8006/endeca_jspref/controller.jsp  (with servername and Port: 15001) Even trie

  • Transport master data

    Hi, How to transport Organization data and Territory data from Dev system to QA system? Thanks Kamal

  • Deleting Mail Folders in Time Machine

    I want to delete all time machine back up files certain selected mail folders and emails. How do I do that? If I open mail in the finder, then enter time machine, the mail folders in a mail window appears in time machine but the action menu in the bo

  • Navigation structure problem

    Dear All, In Portal Information Architecture we have four level we have to display.We are displaying two levels in horizental TLN and remaining in the third level.After creating the pcd objects while adding them to role am facing problem.I tried all