Delete a master page in SharePoint using PowerShell

Had one of my group approach me today inquiring about deleting a master page from a site collection using PowerShell. Quick and simple way to do it…


   1: $web = Get-SPWeb "http://prototype"

   2: $lib = $web.GetFolder("_catalogs/masterpage")

   3: $file = $lib.Files["v4_copy(1).master"];

   4: $file.Delete();

   5: $web.dispose();


So I thought I would share. Enjoy!


About Geoff Varosky
Geoff Varosky is a Senior Architect for Insight, based out of Watertown, MA. He has been architecting and developing web based applications his entire career, and has been working with SharePoint for the past 15 years. Geoff is an active member of the SharePoint community, Co-Founder and Co-Organizer of the Boston Area SharePoint Users Group, co-founder for the Boston Office 365 Users Group, co-organizer for SharePoint Saturday Boston and speaks regularly at SharePoint events and user groups.

One Response to Delete a master page in SharePoint using PowerShell

  1. Get-SPWeb : The term ‘Get-SPWeb’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
    name, or if a path was included, verify that the path is correct and try again.
    At C:\Users\s9070435\Desktop\domaintrust.ps1:1 char:8
    + $web = Get-SPWeb “”
    + ~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: