I need some help output the result of this PowerShell scripts to a file. https://gallery.technet.microsoft.com/office/How-get-the-workflow-7d00eed9#content
I have a similar scripts I use to check execution status of SharePoint 2013 workflow on a list. but I think it will be more productive if can use this PowerShell scripts on TechNet. the scripts found on TechNet works as expected but I think it will be better if I can output result to a file our send the output to an email.
my end goal is to have a scripts that can check the execution status of all workflow within a site and get the status of all workflow that has been executed within the last 4hours and either output the result to a file or send to an email.
My old scripts
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$web = get-spweb -Identity https://mysharepointsite
$list = $web.Lists["my list"]
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$wfs = $sub.EnumerateSubscriptionsByList($list.ID)
$wfis=$wfm.GetWorkflowInstanceService()
$array=@()
foreach ($item in $list.Items)
{
$workflowInstances=$wfis.EnumerateInstancesForListItem($list.ID,$item.ID)
foreach($wf in $workflowInstances)
{
$wfName = $wfs | ?{$_.Id -eq $wf.WorkflowSubscriptionId} | select -ExpandProperty Name
$wfID= $wf.ID
$wfStatus = $wf.Status
$wfListItem = $item.Name
$WFLastUpDateTime=$wf.LastUpdated.ToLocalTime()
$modifiedDateTime = Get-Date $WFLastUpDateTime
if ($modifiedDateTime -gt (get-date).addhours(-4))
{
#write-host "Item Name:$wfListItem, Workflow Name: $wfName, Current Workflow Status: $wfStatus, Last Run: $modifiedDateTime" -f Yellow
$array+="Item Name:$wfListItem, Workflow Name: $wfName, Current Workflow Status: $wfStatus, Last Run: $modifiedDateTime"
}
}
}
$array | Out-File "C:\workflowinfo.txt"