I was helping someone out and went way to far afield, but figured I'd share what I came up with.
This is a script that dumps the logs of NCM jobs to your file system somewhere. There's also a clear option so that you could get a day-by-day log (or by week) instead of having everything all entries in one log file.
$SwisConnection = Connect-Swis -Hostname "myOrionServer.Domain.local" -UserName "myUserAccount" -Password "myComplexPassword"
# Export path for the job logs
$ExportPath = "D:\Scratch\NCMJobLogs"
# Do we want to clear the logs
$ClearLogs = $false
$Swql = @"
SELECT NCMJobID
, NCMJobName
, LastDateRun
FROM Cirrus.NCM_NCMJobsView
WHERE Enabled = 'TRUE'
AND IsHidden = 'FALSE'
AND JobLogIndicator <> 0
$NcmJobs = Get-SwisData -SwisConnection $SwisConnection -Query $Swql
ForEach ( $NcmJob in $NcmJobs ) {
# The GetJobLog Verb requires two parameters:
# The Job ID number
# a boolean for 'checkSize'
$JobLogXml = Invoke-SwisVerb -SwisConnection $SwisConnection -EntityName "Cirrus.NCM_NCMJobs" -Verb "GetJobLog" -Arguments $NcmJob.NcmJobId, $false
# check to see if there's anything 'in' the log
if ( $JobLogXml.'#text' ) {
try {
# Build a file name for the exported log
$FileName = "$( $NcmJob.NcmJobId.ToString("0000") )_$( $NcmJob.NcmJobName )_$( ( $NcmJob.LastDateRun.ToUniversalTime() | Get-Date -Format 's' ).Replace(":", "-") ).log"
# Export the Log to the file system
$JobLogXml.'#text' | Out-File -FilePath ( Join-Path -Path $ExportPath -ChildPath $FileName ) -Force
if ( $ClearLogs ) {
# clear the job logs
Invoke-SwisVerb -SwisConnection $SwisConnection -EntityName "Cirrus.NCM_NCMJobs" -Verb "ClearJobLog" -Arguments $NcmJob.NCMJobID | Out-Null
}
}
catch {
Write-Error -Message "An error occurred in exporting the job log or clearing the logs"
}
finally {
# nothing happening here
}
}
}
Thought it was interesting and possibly worth sharing if people wanted to work with it.