Skip to content

Commit

Permalink
Merge pull request #693 from reshmee011/getfolderitem
Browse files Browse the repository at this point in the history
new script sample to get folder item
  • Loading branch information
pkbullock authored Apr 29, 2024
2 parents c889d7d + 1d4ac30 commit 7eef383
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
56 changes: 56 additions & 0 deletions scripts/spo-get-folder-item/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
plugin: add-to-gallery
---

# Get Folder Item properties

## Summary

This script demonstrates how to use **Get-PnPListItem** to retrieve files properties from large libraries, especially within specific folders, along with their associated properties.

# [PnP PowerShell](#tab/pnpps)

```PowerShell
$SiteUrl = Read-Host -Prompt "Enter site collection URL "; #e.g "https://contoso.sharepoint.com/sites/test"
Connect-PnPOnline -url $SiteUrl -Interactive
$listName = Read-Host -Prompt "Enter the library name, e.g. 'Shared Documents'"
$FolderSiteRelativeURL = Read-Host -Prompt "Enter relative folder url starting with *, e.g. '*Shared Documents/folder' "; #e.g."*Shared Documents/folder/subfolder-folder/subfolder-subfolder-folder*"
$list = Get-PnPList $listName
$global:counter = 0
#Retrieving all items within the folder which is not a folder
$items = Get-PnPListItem -List $listName -PageSize 500 -Fields FileLeafRef,FileRef,PPF_Comments -ScriptBlock `
{ Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete `
($global:Counter / ($List.ItemCount) * 100) -Activity "Getting folders from List:" -Status "Processing Items $global:Counter to $($List.ItemCount)";} `
| Where {$_.FileSystemObjectType -ne "Folder" -and $_.FieldValues.FileRef -like $FolderSiteRelativeURL}
$type = [System.Collections.ArrayList]@();
$items | foreach-object {
if($_.FieldValues.Issue_Comments){
if($type -notcontains $_.FieldValues.Issue_Comments){
$type.Add([PSCustomObject]@{
Name = $_.FieldValues.Issue_Comments
});
write-host $_.FieldValues.Issue_Comments;
}
}
}
$type | Export-Csv -Path "C:\temp\categories.csv" -NoTypeInformation -Force -Delimiter "|"
```

[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]

***
## Source Credit

Sample first appeared on [Pnp Powershell Get Folder Item](https://reshmeeauckloo.com/posts/pnp-powershell-get-folder-item/)

## Contributors
| Author(s) |
|-----------|
| [Reshmee Auckloo (script)](https://github.com/reshmee011)|

[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-get-folder-item" aria-hidden="true" />
Binary file added scripts/spo-get-folder-item/assets/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/spo-get-folder-item/assets/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions scripts/spo-get-folder-item/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
{
"schema": null,
"name": "spo-get-folder-item",
"version": null,
"source": "pnp",
"title": "Retrieves all files properties within a specified folder.",
"url": "https://pnp.github.io/script-samples/spo-get-folder-item/README.html",
"creationDateTime": "2024-04-27",
"updateDateTime": "2024-04-27",
"shortDescription": "Retrieves all files properties within a specified folder.",
"longDescription": ["An alternative to The **Get-PnPFolderItem** cmdlet which does not work with large libraries. To circumvent the limitations of Get-PnPFolderItem, Get-PnPListItem can be used. This cmdlet enables efficient retrieval of files from large libraries, especially within specific folders, along with their associated properties."],
"products": [
"SharePoint"
],
"categories": [
"Configure"
],
"tags": [
"Connect-PnPOnline",
"Get-PnPList",
"Get-PnPListItem"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "2.3.0"
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-get-folder-item/assets/preview.png",
"alt": "preview image for the sample",
"slides": null
}
],
"authors": [
{
"gitHubAccount": "reshmee011",
"company": "",
"pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4",
"name": "Reshmee Auckloo"
}
],
"references": [
{
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
},
{
"name": "Want to learn more about CLI for Microsoft 365 and the commands",
"description": "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.",
"url": "https://aka.ms/cli-m365"
}
]
}
]

0 comments on commit 7eef383

Please sign in to comment.