Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. if ($ErrLog.Length -ne 0)
  2. {
  3. $ErrLog | ForEach-Object {
  4.  
  5. # Gather details of interest.
  6. $ErrTarget = $_.TargetObject
  7. $ErrReason = $_.CategoryInfo.Reason
  8.  
  9. # Write data to custom PowerShell object.
  10. $ErrObject = New-Object PSObject
  11. $ErrObject | Add-Member -MemberType NoteProperty -Name 'Target Path' -Value $ErrTarget
  12. $ErrObject | Add-Member -MemberType NoteProperty -Name 'Error Reason' -Value $ErrReason
  13.  
  14. # Add error to log variable.
  15. $ErrList += $ErrObject
  16. }
  17. }
  18.  
  19. # Announce number of errors, and write to log as needed.
  20. if ($ErrList.Length -eq 0)
  21. {
  22. Write-Output "No errors encountered.`n"
  23. }
  24. else
  25. {
  26. $ErrList | Export-CSV $LogErrors -NoTypeInformation
  27. $ErrorsCount = $ErrList.Length
  28. Write-Output "Logged $ErrorsCount errors.`n"
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement