-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #693 from reshmee011/getfolderitem
new script sample to get folder item
- Loading branch information
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
] |