Create a ps1 extension file and save it in your local path.
Change the highlighted part with your site collection URL, List name etc.
- <ol>
- <li>Create a ps1 extension file and save it in your local path.</li>
- </ol>
- <p>Change the highlighted part with your site collection url, List name etc.</p>
- <p>#============================================================</p>
- <p># Function Get-FolderItems is a recursive function that will</p>
- <p># get all items from a list and print it out like a Treeview</p>
- <p>#============================================================</p>
- <p>function Get-FolderItems([Microsoft.SharePoint.SPFolder]$folder, $level) {</p>
- <p>#The following code is to simulate the treeview in the printout. It if for visual purposes only</p>
- <p>if($level -eq $null) {</p>
- <p>$level=0</p>
- <p>}</p>
- <p>$prestring = “”</p>
- <p>for($x=0;$x -le $level;$x++) {</p>
- <p>$prestring += “—”</p>
- <p>}</p>
- <p># Create query object</p>
- <p>$query = New-Object Microsoft.SharePoint.SPQuery</p>
- <p>$query.Folder = $folder</p>
- <p># Get SPWeb object</p>
- <p>$web = $folder.ParentWeb</p>
- <p># Get SPList</p>
- <p>$list = $web.Lists[$folder.ParentListId]</p>
- <p># Get a collection of items in the specified $folder</p>
- <p>$itemCollection = $list.GetItems($query)</p>
- <p># If the folder is the root of the list, display information</p>
- <p>if($folder.ParentListID -ne $folder.ParentFolder.ParentListID) {</p>
- <p>Write-Host($folder.Name + ” [Root of the list with ” + $folder.ItemCount + ” item(s) in it]”)</p>
- <p>}</p>
- <p># Iterate through each item in the $folder – Note sub folders and list items are both considered items</p>
- <p>foreach($item in $itemCollection) {</p>
- <p># If the item is a folder</p>
- <p>if($item.Folder -ne $null) {</p>
- <p># Write the Subfolder information</p>
- <p>Write-Host($prestring + “*” + $item.Name + ” [Folder Item | Parent Folder: ” + $folder.Name + ” | Contains ” + $folder.ItemCount + ” item(s)]”)</p>
- <p># Call the Get-Items function recursively for the found sub-solder</p>
- <p>Get-FolderItems $item.Folder ($level+1)</p>
- <p>}</p>
- <p># If the item is not a folder</p>
- <p>if($item.Folder -eq $null) {</p>
- <p># Write the item information</p>
- <p>Write-Host($prestring + $item.Name + ” [Item | Parent Folder: ” + $folder.Name + “]”)</p>
- <p>}</p>
- <p>}</p>
- <p>$web.dispose()</p>
- <p>$web = $null</p>
- <p>}</p>
- <p>#============================================================</p>
- <p># Function Get-Folder will return a SPFolder object based on</p>
- <p># $webUrl string and a $listName string</p>
- <p>#============================================================</p>
- <p>function Get-Folder([string]$webUrl,[string]$listName) {</p>
- <p># Use the Get-SPWeb CMDLET – it gives you the SPWeb object without having to create the SPSite object</p>
- <p>$web = Get-SPWeb $stringUrl</p>
- <p># Get your SPList</p>
- <p>$list = $web.Lists[$stringListName]</p>
- <p># Get the root folder containing items in your list</p>
- <p>$folder = $list.RootFolder</p>
- <p>$web.Dispose()</p>
- <p>$web = $null</p>
- <p>return ,$folder</p>
- <p>}</p>
- <p>#============================================================</p>
- <p># Main procedural code</p>
- <p>#============================================================</p>
- <p>$stringUrl = “http:
- <p>$stringListName = “Calander”</p>
- <p># Get the root folder for the List</p>
- <p>$folder = Get-Folder $stringUrl $stringListName</p>
- <p># Call the recursive Get-FolderItems function passing the root of your list. It will call itself again and again until it has gone through your entire structure</p>
- <p>Get-FolderItems $folder2. Open Management Shell as an administrator.</p>
- <ol start="3">
- <li>Run the PS script using the path along with the file as shown.</li>
- </ol>
- <ol start="4">
- <li>Here is the required output.</li>
- </ol>
- <p>Use <a href="http://htmlcheatsheet.com/" target="_blank" rel="nofollow">the HTML Cheat Sheet</a> for color picker, search for special HTML characters, get examples of the most common tags and generate any tags.</p>
Get-FolderItems $folder2. Open Management Shell as an administrator.
Run PS script, using the path along with the file, as shown below.
Here, the required output is given below.