QlikView – Open, Save, Close a QVW without reloading data using PowerShell

So you can open a QVW file from the command line with one of the following options

/r Reload, save, close.
/rp Partial-Reload, save, close.
/l Reload, leave open.
/p Partial-Reload, leave open.
/v Pass variable.

None of these options suited me, what I wanted was the following; Open QVW, immediately save it without doing anything i.e. not reloading data, not open script, nothing… then close the file. I was pointed towards the Automation Documentation over here http://community.qlikview.com/docs/DOC-1793 and I was provided with a macro that uses the COM Object in one QVW that opens, saves and closes another QVW. This solved the problem and could be called from the command line.

I didn’t like this solution as it was a bit hacky… Having one file call another etc etc, and I use PowerShell for the rest of my automation; I figured there has to be a PowerShell solution and came up with the following script:

function qv-SaveAndClose-QVW
{
 param(
  [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
  $QvwPath
 )
 $qvComObject = new-object -comobject QlikTech.QlikView
 $NewDoc = $qvComObject.OpenDoc("$QvwPath")
 $NewDoc.Activate()
 $NewDoc.Save()
 $NewDoc.CloseDoc()
 $qvComObject.Quit()
}