Q:

Powershell: Upload .html Master Page and generate .master

I am attempting to upload a new Master Page to a SharePoint 2013 site using Powershell.
I am copying the .html file to the "Master Page Gallery" list successfully but I cannot find any way of having the .master file generated without manually visiting the Design Manager in my web browser.
Is it possible to upload a .html Master Page through Powershell and have the .master generated so I can set it as the default Master Page?

A:

I found I needed to add it, check it out, call update, check it in and publish it. So:
    $web = Get-SPWeb $site

    $folder = $web.getfolder("_catalogs/masterpage")
    $files = $folder.Files
    $mPage = Get-Item "C:\path to your\masterpage.html"
    $file = $files.Add("masterpage.html", $mPage.OpenRead(), $true)
    $file.CheckOut()        
    $file.update()
    $file.CheckIn("")
    $file.Publish("")

