The code I am using is below. The code works fine and does what I want it to do except for the try/catch portion. I'm using SCCM 2016, Windows 10 Enterprise 1709 and PowerShell v5. The main problem is that when I run the script through "Run Script" in the Configuration Manager Console, the script runs but does not write the report file on the target server. I examined the log files on the server and on the client and I get an exit code of 0, which means successfully ran. I added the FQDN to eliminate the possibility of that being the problem. I shared the folder location and gave full rights to all users to ensure the folder could be found. There are no errors or any indication as to why the report isn't written to the target path. I tested this path by running it from the "Run Script" in Config Console and changing the location for the output to land to c:\Temp and it works fine. I would like assistance resolving why the report file is not writing to target path. Thank you.
Set-ExecutionPolicy Bypass
$env:COMPUTERNAME = HostName
$DeplPath = "AppData\LocalLow\Sun\Java\Deployment\deployment.properties"
$javausers = foreach ($User in Get-ChildItem C:\Users -Directory){
$folder = Join-Path $User.FullName $DeplPath
if (Test-Path $folder) {
$TestResult = "True - deployment.properties"
} Else {
$TestResult = "False - Path not found"
}
[PSCustomObject]@{
"Computer Name" = $env:COMPUTERNAME
"Results" = $TestResult
"Users" = $user.Name
}
}
#$javausers
try
{
$javausers | Export-Csv -NoTypeInformation -Path "\\ourserver.domain.com\d$\Java_User_Reports\JavaUsersList.csv" -Append
}
catch
{
$javausers | Export-Csv -NoTypeInformation -Path "\\ourserver.domain.com\d$\Java_User_Reports\JavaUsersList.csv" -Append
}