nightroman / SplitPipeline

Parallel Data Processing in PowerShell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transcription error while running script using Split-Pipeline

hmiller10 opened this issue · comments

I am using the following code to test Split-Pipeline to inventory my certificate authority server databases.
$ScriptBlock = {

begin
{
	
	#Set loop specific variables
	
	$certProps = @("Request.RequesterName", "CommonName", "ConfigString", "NotBefore", "NotAfter", "RequestID", "SerialNumber", "CertificateTemplateOID")
	[int32]$pageSize = 100000
	#$colRequests = @()
	[int32]$pageNumber = 1
	$r = 0
	
}
process
{
	$CA = $_
	Write-Verbose -Message "Working on search of $CA" -Verbose
	try
	{
		Do
		{
			Get-CertificationAuthority -ComputerName $CA -ErrorAction Stop -ErrorVariable CAConnectError | Get-AdcsDatabaseRow -Table Issued -Property $certProps `
																										-Filter "NotBefore -ge $((Get-Date).AddMonths(-30))", "NotAfter -le $((Get-Date).AddMonths(2))", `
																										"Request.RequesterName -ge 'US\'", "Request.RequesterName -lt 'UT

Transcript_error
'" -Page $pageNumber -PageSize $pageSize -ErrorAction Continue | Select-Object -Property $certProps |
Sort-Object -Property NotBefore | ForEach-Object {
#[Array]$colRequests += $; $r++
Return $
; $r++
}
$pageNumber++

		}
		While ($r -eq $pageSize)
		if ($null -ne $CAConnectError)
		{
			Write-Error -Message $CAConnectError
		}
		#Return $colRequests
		
	}
	catch
	{
		$errorMessage = "{0}: {1}" -f $Error[0], $Error[0].InvocationInfo.PositionMessage
		Write-Error $errorMessage -ErrorAction Continue
	}
	
	
}
end
{
	[System.GC]::GetTotalMemory('forcefullcollection') | Out-Null
}

}

#Process CA Reports
$ReportResults += $CAs | Split-Pipeline -Module PSPKI -Script $ScriptBlock

#Define output file
$fileStamp = (Get-Date).ToString("yyyy-MM-dd_HH-mm-ss")
$csvFileName = "MF_CertInfo_as_of_$($fileStamp).csv"
$csvFile = "{0}{1}" -f $workingDir, $csvFileName

$ReportResults | Select-Object -Property Request.RequesterName, CommonName, ConfigString, NotAfter, NotBefore, RequestID, SerialNumber, @{ Name = "CertificateTemplate"; Expression = { $_.CertificateTemplateOID.FriendlyName } } | Export-Csv -Path $csvFile -NoTypeInformation

#Compress the CA daily backup folder into a single archive
$fileStamp = (Get-Date).ToString("yyyy-MM-dd_HH-mm-ss")
$archiveFileName = "MF_CertInfo_for_$($fileStamp).zip"
$archiveFile = "{0}{1}" -f $usCertRptFldr, $archiveFileName

If ((Test-Path -Path $archiveFile -PathType Leaf) -eq $true) { Remove-Item -Path $archiveFile -Confirm:$false }
#See https://msdn.microsoft.com/en-us/library/hh875104(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[IO.Compression.ZipFile]::CreateFromDirectory($workingDir, $archiveFile, $compressionLevel, $false)

#If ((Test-Path -Path $archiveFile -PathType Leaf) -eq $true)
If (([IO.Compression.ZipFile]::OpenRead($archiveFile).Entries.Name) -match $csvFileName)
{
[String]$status = "Success"
}
Else
{
[String]$status = "Failed"
}

#Stop transcript
Stop-Transcript -ErrorAction SilentlyContinue

This issue does not occur with any other scripts I use similar code in. The oddest part is that the transcript file actually does complete and I am able to attach it to an e-mail to read later on. I have attached a screenshot of the error output from the console

Am I doing something wrong? Are others seeing this behavior.

Where is the transcript started? From your code (a little difficult to read :)) it looks like you are stopping it but not stating. And the error tells you something similar ~ "you have not started transcript but try to stop it".

@hmiller10

Split-Pipeline is not against transcription, as such.
Here is the working example: https://github.com/nightroman/SplitPipeline/blob/master/Tests/Test-Transcript.ps1

Apparently something in your script disagrees with transcription.
Maybe due to running with Split-Pipeline, maybe not. I cannot tell.
Like I said, Split-Pipeline works with transcript, at least in simple scenarios.

Try to run the script without Split-Pipeline

# try to replace this:
$ReportResults += $CAs | Split-Pipeline -Module PSPKI -Script $ScriptBlock

# with this:
$ReportResults += $CAs | & $ScriptBlock

If this run has the same error then it's definitely not due to Split-Pipeline.
If it does not have the error, this proves that Split-Pipeline contributes to the reasons.
But it does not mean it is the culprit, there are many moving parts in your scenario.
And to be honest, from my experience, PowerShell transcription is not that reliable.

Unfortunately, I do not see how to help you, apart from giving the above notes.
Do not use transcript if it misbehaves, use some different form of logging.


P.S. You may zip large scripts and attach to comments (e.g. by drag-and-drop).

@hmiller10
I am closing the issue. Please feel free to reopen if you have more details.