【发布时间】:2021-12-21 02:21:40
【问题描述】:
此脚本循环遍历 powershell 中的每个文件夹并检查该文件夹是否具有通配符文本,然后将文件位置输出到 csv。
我得到的错误是:Export-Csv:无法将参数绑定到参数“InputObject”,因为它为空。
还有一些包含通配符的文件夹。大多数情况下,在级别 3 - 4 - 5 中,它甚至在输出中都没有检测到强硬,我看到一个包含该单词的文件夹。 提前致谢!
Import-Module PnP.PowerShell
#Config Parameters
$SiteURL= "*******/sites/Archief"
$Folder = "Gedeelde Documenten"
$Pagesize = "500"
Connect-PnPOnline -Url $SiteURL -Interactive ### Change to your specific site ###
#Output path
$outputPath = "C:\users\$env:USERNAME\Desktop\test.csv"
Function GetFolders($folderUrl)
{
$folderColl=Get-PnPFolderItem -FolderSiteRelativeUrl $folderUrl -ItemType Folder
# Loop through the folders
foreach($folder in $folderColl)
{
$newFolderURL= $folderUrl+"/"+$folder.Name
if ($newFolderURL -cnotlike "*archief*"){
write-host -ForegroundColor Green $folder.Name " - " $newFolderURL
$DocLibs = Get-PnPList | Where-Object {$_.BaseTemplate -eq 101}
#Loop thru each document library & folders
$results = @()
foreach ($DocLib in $DocLibs) {
if ($DocLib -cnotlike "*archief*"){
$AllItems = Get-PnPListItem -List $DocLib -Fields "FileRef", "File_x0020_Type", "FileLeafRef" -PageSize 500
#Loop through each item
foreach ($Item in $AllItems) {
if ($Item["FileRef"] -cnotlike "*archief*" -or $Item["FileLeafRef"] -cnotlike "*archief*" -and ($Item["File_x0020_Type"])){
Write-Host "File found. Path:" $Item["FileRef"] -ForegroundColor Green
#Creating new object to export in .csv file
$results += New-Object PSObject -Property @{
Path = $Item["FileRef"]
FileName = $Item["FileLeafRef"]
FileExtension = $Item["File_x0020_Type"]
}
}
}
}
}
GetFolders($newFolderURL)
}
}
}
$results | Export-Csv -Path $outputPath -NoTypeInformation
GetFolders($folder)
【问题讨论】:
标签: powershell sharepoint