PowerShell Logging / Error Handling
Hi All!
So I am trying to create a PowerShell step in PDQ and I am having a hard time with the output log. Here is a sample of my code.
Write-Output "Starting Script" # I have tried Echo's instead as well
Try {
[XML]$Output = .\BiosConfigUtility64.exe /getvalue:"TPM Device"
$TMPDevice = Select-Xml -Xml $Output -XPath "//VALUE" | foreach {$_.node.InnerXML}
IF ($TMPDevice -eq "<![CDATA[*Hidden,Available]]>")
{
Write-Output "Enabling TPM Device"
.\BiosConfigUtility64.exe /cpwdfile:default_password.bin /setvalue:"TPM Device","Available"
}ELSE{
Write-Output "TPM Device is Available"
}
}Catch {
$_.Exception #I have also tried just $_
exit 6
}
Ultimately I understand the exe command on line 8 is causing the exception but I am trying to understand how to handle this properly.
I guess I am not asking how to fix the exe exception and trying to figure out how to get data into my output.log. No matter what output type or error type I use I do not get any output log. I would hope to at least see "Starting Script"

For this script I would like to see the following in the Output Log.
Starting Script
Enabling TPM Device
<BIOSCONFIG Version="" Computername="#######" Date="2020/05/14" Time="23:42:16" UTC="20">
<SUCCESS msg="Successfully read password from file" />
<SETTING changeStatus="fail" name="TPM State" returnCode="4">
<OLDVALUE><![CDATA[Disable]]></OLDVALUE>
<VALUE><![CDATA[]]></VALUE>
</SETTING>
<ERROR msg="An operation failed" />
<ERROR msg="BCU return value" real="4" translated="4" />
</BIOSCONFIG>
#and maybe some exception code down here for $_
Is what I am looking for even possible? I just find error handling hard in PDQ. Once I write my PowerShell our deployment users may not understand the errors and how to move forward. This way I can enter my own error handling and they can see in plain text what broke and what needs to be done manually.
Any help would be great.
Thanks!
Comments
Breaking it down to its simplest form:
Hmm, Thanks for the response Ben.
I was working with support on this issue as well since I was not able to get output.log's. I narrowed this down to something similar.
I didn't post my entire code but I am working on an error a bit higher up in sequence same error different switches for the exe.
The EXE would output
This is where I was receiving weird error results in PDQ.
After dumping all properties of $_ I was able to locate this error which was being suppressed by both PS/ISE at least on my computer.
After Adjusting my code to
Everything is working as intended now.
I hope the same can be said for
$Output = .\BiosConfigUtility64.exe /getvalue:"TPM Device"I will post an update if this works for the TPM Device as well.