I have task with powershell script in it but, when it fails on following lise I would like to capture Write-error(see highlate din bold) message to optput properties in Altiris console. Is there any easy way to do this?
see attached full script
if ($Username -eq "Administrator" -Or $UserPrefix -eq "SUP")
{
$ErrorActionPreference = "Stop"
Write-Error "Local Administrator or SUP account is logged in, we are not adding local administrator/sup account again, Log file(C:\LabIT\AdminRights_Enabled.txt) will not be updated"
} Else {
# Add logged in user to group & write user information to log file
$objGroup.PSBase.Invoke("Add",$objUser.PSBase.Path)
$Domain + "\" + $Username + "\" + $date | Out-File $LogFile
}
I would like to capture this at following location and only shows failed but, nothing in Output properties: