如何从powershell中获取SharePoint的元数据(列值)



我试图获得元数据(列值)为每个文件在powershell(参考图像和代码到现在)在运行下面的代码名称时,我得到,但如果我尝试只打印名称,则其他值…

$File.Name + $File.FieldValues.Hash | Format-Table

是否有任何方法可以从文件夹中每个文件的列中获取所有值?-

代码到现在-

Import-Module SharePointPnPPowerShellOnline
#Get Connection to the url , #Connect-PnPOnline $URL 
Connect-PnPOnline "Some SharePoint Url" -UseWebLogin
$SharePointFolderPath = "Some folder in Shared Documents"
$FolderItems = Get-PnPFolderItem -ItemType file -Recursive -FolderSiteRelativeUrl $fileURL
foreach($file in $FolderItems){
#$File = Get-PnPFile -Url $fileURL -AsListItem -ErrorAction SilentlyContinue #by using this and giving the exact path/Filename.txt the values are coming for only that file but not for all the files.. but not with get folder items also.
$File.Name #Only name is coming 
$File.Hash #Hash column is custom created by myself but its not returning anything other than null,the actual value should be returned.
#$File
}

元数据列的截图

正如我在您的另一个问题中回答的那样,您可以为hash列尝试此操作

$FolderItems = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderURL -ItemType File -Recursive
ForEach($File in $FolderItems){
$File.Name
$fileURL=$FolderURL+"/"+$File.Name
$fileItem=get-pnpfile $fileURL -AsListItem
$fileItem['Hash']
}

这里有一个链接可能会有所帮助。下面是我在使用Get-FileMetaData函数学习元数据时使用的脚本。它在PowerShell图库中,我认为运行它是安全的。

第一次运行:Install-Module -Name PSSharedGoods来自作者的例子:

Get-ChildItem -Path $Env:USERPROFILEDesktop -Force | Get-FileMetaData -Signature | Out-HtmlView -ScrollX -Filtering -AllProperties

然后我是这样使用他们的函数的:

$folder = Get-ChildItem
foreach($File in $folder) {
$fileMetaProperties = @($(Get-FileMetaData $File | Select-Object -Property Name,Title))
$a = $fileMetaProperties.Name
$b = $fileMetaProperties.Title
Write-Output "$a and $b"
}

祝你好运!

最新更新