Author Posts

April 6, 2016 at 8:32 pm

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.

April 6, 2016 at 10:36 pm

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