How to get metadata(Column Value) in SharePoint from powershell

Viewed 656

I am trying to get the metadata(column values) for each file in powershell (refer image and code till now) While running the below code name i am getting, but other values if i try like only the name is priniting..

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

is there any way to get all the values from the columns for every file in the folder ? -

Code Till Now -

   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
}

ScreenShot for the metadata column

2 Answers

Here is a link that might help. Below is a script I was playing with while learning about Metadata using the Get-FileMetaData function. It's in the PowerShell Gallery and I think it is safe to run.

First run: Install-Module -Name PSSharedGoods Example from the author:

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

Then this is how I was using their function:

$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"
}

Good Luck!

As I answered in your another question, you could try this for the hash column

 $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']
}
Related