1

How do I download a masterpage file using PowerShell?

e.g. URL: http://sharepoint/_catalogs/masterpage/file.master

1 Answer 1

2

To list all master pages:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;

Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, MasterUrl

To download a specific file / master page:

$fromsite = "<your sp url>"

$fromfile = "/_catalogs/masterpage/seattle.master"
$tofile   = "c:\seattle.master"

$web = Get-SPWeb $fromsite
$file = $web.GetFile($fromfile)
$filebytes = $file.OpenBinary()

$filestream = New-Object System.IO.FileStream($tofile, "Create")
$binarywriter = New-Object System.IO.BinaryWriter($filestream)
$binarywriter.write($filebytes)
$binarywriter.Close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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