0

I have document library which contains multiple content Types.

Is it possible to get the documents or documents all metadata field value using PowerShell Script?

Is it possible to identify which column belongs to which content type using a PowerShell Script?

Please suggest some PowerShell scripts.

2

Using below script you can get the documents metadata fields value . you can store it on your local machine. create text file with name MetaDataDieldValues to save metadata fields

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
$webUrl = "http://site"
$library = "DocumentsLibrary" 
$s = new-object Microsoft.SharePoint.SPSite($webUrl)    
$w = $s.OpenWeb()         
$l = $w.Lists[$library]  

Write-Host "Connecting To Site: " $webUrl  

//Create variable array $myArray to save metadata field values 
$myArray = @()
//iterate through Document Library
foreach ($listItem in $l.Items)
{
  $currentItemID=$listItem.ID 

   Write-Host "    Current Item ID: " $currentItemID -ForegroundColor DarkYellow

 //Add metadata field value in myarray array seprated by @ symbol

 $myArray += $listItem.Title +"@"+$listItem["Training_x0020_Date"]+"@"+$listItem["Status"]
 Write-Host ""
 Write-Host "Current Item Values seprated By commas: " $myArray  -ForegroundColor Cyan     

}

//Finally add metadata field values in text  file 

$myArray| Out-File "C:\MetaDataDieldValues.txt" -width 120

Write-Host ""
 Write-Host   "Script execution done !"  -BackgroundColor Green

SharePoint 2010 | Powershell | Download all files in document library to Network Share (File share)

$destination = "C:\\tools\\Folder"
$webUrl = "<Url of the specific site>"
$listUrl = "<Url of the specific list. This url is complete Url and NOT relative url>"

$web = Get-SPWeb -Identity $webUrl
$list = $web.GetList($listUrl)

function ProcessFolder {
param($folderUrl)
$folder = $web.GetFolder($folderUrl)
foreach ($file in $folder.Files) {
    #Ensure destination directory
    $destinationfolder = $destination + "/" + $folder.Url 
    if (!(Test-Path -path $destinationfolder))
    {
        $dest = New-Item $destinationfolder -type directory 
    }
    #Download file
    $binary = $file.OpenBinary()
    $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
    $writer = New-Object System.IO.BinaryWriter($stream)
    $writer.write($binary)
    $writer.Close()
    }
 }

#Download root files
ProcessFolder($list.RootFolder.Url)

 #Download files in folders

  foreach ($folder in $list.Folders) {
 ProcessFolder($folder.Url)
                                   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.