error Handling

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Yuan Li Yuan Li 5 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37344
    Profile photo of amit aman
    amit aman
    Participant

    Hi Team,

    I am trying to print the error by using $Error variable, I am able to print the error, but want to know from which server, the following error is coming.
    I am using following code;

    Invoke-Command -ComputerName $vm -ScriptBlock {get-childitem -Path C:\inetpub\logs\LogFiles\ -recurse $vm | where-object {$_.lastwritetime -lt (get-date).addDays(-300)} | Foreach-Object { del $_.FullName } }

    Kindly help me to get the error message along with the server name.

    #37347
    Profile photo of Yuan Li
    Yuan Li
    Participant

    Hey Amit

    I normally use something like

    Invoke-Command -ComputerName $vm -ScriptBlock {get-childitem -Path C:\inetpub\logs\LogFiles\ -recurse $vm | where-object {$_.lastwritetime -lt (get-date).addDays(-300)} | Foreach-Object { del $_.FullName } } -ErrorAction SilentlyContinue -ErrorVariable err
    $err.targetobject
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.