![](/img/trans.png)
[英]Powershell PnP - login to Sharepoint online and download file
[英]SharePoint OnLine - PowerShell PNP - List folders that have attribute
$siteURL="https://URL"
$folder="/FOLDER"
Function GetFolders($folderUrl)
{
$folderColl=Get-PnPFolderItem -FolderSiteRelativeUrl $folderUrl -ItemType Folder
# Loop through the folders
foreach($folder in $folderColl)
{
write-host -ForegroundColor Green $folder.Name
}
}
# Connect to SharePoint Online site
Connect-PnPOnline -Url $siteURL -Credentials (Get-Credential)
# Call the functions
GetFolders($folder)
我正在嘗試從下面的選項卡中列出包含字符串的文件夾。 例如,字符串是“important_documents”
我已設法列出所有內容,但缺少完成腳本的 powershell 知識:)
我的文檔庫:
請以管理員身份運行以下 PowerShell 腳本:
#Variables
$SiteURL = "https://xxxx.sharepoint.com/sites/sitename"
$LibraryName = "{libraryname}"
Try {
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Library
$Library = $Ctx.web.Lists.GetByTitle($LibraryName)
$Folders = $Library.RootFolder.Folders
$Ctx.Load($Folders)
$Ctx.executeQuery()
#Get the Folder by Name
$Folder = $Folders | Where {$_.Name -like "*important_documents*"}
foreach($Fol in $Folder){
#Get Some Folder Properties
Write-host "Folder Name:"$Fol.Name
Write-host -f Green "Total Number of Files in the Folder:"$Fol.ItemCount
Write-host ""
}
}
Catch {
write-host -f Red "Error Getting Folder!" $_.Exception.Message
}
$siteURL="https://URL"
$folder="/FOLDER"
Function GetFolders($folderUrl)
{
$folderColl=Get-PnPFolderItem -FolderSiteRelativeUrl $folderUrl -ItemType Folder
# Loop through the folders
foreach($folder in $folderColl)
{
$newFolderURL= $folderUrl+"/"+$folder.Name
GetFolders($newFolderURL)
$a = $newFolderURL
if($a -like "*important_documents*"){
write-host -ForegroundColor Green $a
Get-PnPList | Where {$_.Hidden -eq $false}
}
}
}
# Connect to SharePoint Online site
Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)
# Call the functions
GetFolders($folder)
更新:我設法列出了所有包含 important_documents 的文件夾和子文件夾。 在 mu 的情況下,它運行緩慢,因為我有很多子文件夾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.