Export-CSV fail

I’ve been trying to run powershell code from within PSADT as an application install. It runs perfectly outside of SCCM but, when executed as an SCCM application it always fails when trying to export a csv. It is not an application install though. It just gathers information from each computer and exports it to the csv.

This is the line that fails -
$addIns | Export-Csv -Path $reportPath -NoTypeInformation
I’ve verified that all of the variables are populated correctly.

Unfortunately the error produced is a bit vague -

[Installation] :: Error Record:
-------------At C:\WINDOWS\ccmcache\2o\Deploy-Application.ps1:218 char:11
+ $addIns | Export-Csv -Path $reportPath -NoTypeInformation
+

Any help would be appreciated.

Andy

what is $addins supposed to be? string? object? i’d go back to see where it’s being populated to see if it’s working properly adding in some log/debug lines around it (checking for type, if it has what is expected, etc).

I’m always amazed how Powershell code from a simple script magically fails when added into Deploy-Application.ps1.
Usually it’s because the simple script can only handle one perfect scenario.

I’m guessing $addIns is not what you or Export-CSV is expecting. $#it happens in PROD when you are not there. No logging = no clues so let’s force some logging in.

Write-Log "# of entries in `$addIns [$($addIns.count)]"
Write-Log "Exporting to [$reportPath]..."
#Using the easy way to force a Powershell command to send results info to the PSADT log file
$addIns | Export-Csv -Path $reportPath -NoTypeInformation -Verbose *>&1 | Out-String | Write-Log
Write-Log "Success!"

I know it looks like overkill but when the tech-clueless in charge wants answers, you need hints as to how far the script ran before it blew up.

Thank you for the suggestion. I’ll use your code to see if I can get more information out of it.

1 Like