Creating a Workflow Report and Placing into Default Container

Someone asked if you could use powershell to generate a workflow status report and save it into the workflow's default container..... yes you can!

Add-Type -Path "D:\Program Files\Hewlett Packard Enterprise\Content Manager\HP.HPTRIM.SDK.dll"
$iseProc = Get-Process -id $pid
$db = New-Object HP.HPTRIM.SDK.Database
$wfs = New-Object HP.HPTRIM.SDK.TrimMainObjectSearch -ArgumentList $db, Workflow
$wfs.SearchString = "all"
$report = New-Object HP.HPTRIM.SDK.Report -ArgumentList $db, "Workflow Report"
$docRt = New-Object HP.HPTRIM.SDK.RecordType -ArgumentList $db, "Document"
foreach ( $wf in $wfs ) 
{
    if ( ([HP.HPTRIM.SDK.Workflow]$wf).DefaultContainer -ne $null ) 
    { 
        $wfc = New-Obect HP.HPTRIM.SDK.TrimMainObjectSearch -ArgumentList $db, Workflow
        $wfc.SearchString = "uri:$(([HP.HPTRIM.SDK.Workflow]$wf).Uri)"
        $pdf = $report.PrintReportToPdf($wfc)
        $pdfRec = New-Object HP.HPTRIM.SDK.Record -ArgumentList $db, $docRt
        $pdfRec.TypedTitle = "Workflow Report"
        $pdfRec.SetDocument($pdf)
        $pdfRec.SetContainer(([HP.HPTRIM.SDK.Workflow]$wf).DefaultContainer)
        $pdfRec.Save()
        $pdfRec.Dispose()
    }
}
$db.Dispose()