If anyone is interested on one possible solution to this then I did it like this:
1) Powershell script which is looping through each needed site collection, setting up the last activity date before value into the variable and calling a batch file with this data to execute the PurgeWorkflowData command
if (!$PSScriptRoot) { $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent }
$logFilePath = $PSScriptRoot + "Log_file.txt"
"Log" | Out-File $logFilePath -Force
$binary = "`"" + $PSScriptRoot + "PurgeWfDataTest.cmd`""
$urls = "http://domain/sites/00001","http://domain/sites/00002"
$date = (Get-Date).AddDays(-30).ToString("MM/dd/yyyy")
foreach ($url in $urls) {
write-output "& $binary $url $date $PSScriptRoot"
Invoke-Expression "& $binary $url $date $PSScriptRoot"
$url | Out-File -Append -FilePath $logFilePath
}
2) PurgeWfDataTest.cmd file which is being called from the PS script
cd %3
"C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15BINNWAdmin.exe" -o PurgeWorkflowData -siteCollectionUrl %1 -lastActivityBeforeLocal %2 -state Completed < %3PurgeWfDataTest-answer.txt
3) PurgeWfDataTest-answer.txt file containing just 'y' to confirm the NWAdmin.exe command called in point 2.
All files in one folder, windows task running the PS script.
Hi Markan,
This is awesome i have created same thing as per your instructions i have scheduled PowerShell in windows task scheduler, when through PowerShell console i am calling your PowerShell script it triggering cmd file as expected and doing job.
Now problem i am facing when it is scheduled through task scheduler and when doing run from task scheduler it is showing only showing status, its is not going end somewhere or stopping .. just showing running.
Can you tell me any thing i am doing wrong or missing here.
Thanks
Girish K.