I'm trying to set up a Powershell monitor to check whether 4 files are written to a specific directory daily. The Powershell code:
$d = (get-date).Day; $m = (get-date).Month; $y = (get-date).Year; $cnt = (gci \\${IP}\c$\Temp\success\ | where-object {(($_.LastWriteTime).Day -eq $d) -and (($_.LastWriteTime).Month -eq $m) -and (($_.LastWriteTime).Year -eq $y)}).Count; Write-Host 'Statistic: ' $cnt; if ($cnt -eq 4) { exit(0) } else { exit(1) }
When I run this (with the slight change that I use a pair of Write-Host statements instead of the exit statements) locally on the poller, it completes without errors. When I run it in the Powershell monitor component, I get this result:
Testing on node [server]: failed with 'NotAvailable' status
The script returned status code DOWN.
PowerShell Execute Result: ================================
Output: ==============================================
Statistic:
Error: ==============================================
Get-ChildItem : Cannot find path '\\[server ip]\c$\Temp\success\' because it does not exist.
At line:1 char:78
+ $d = (get-date).Day; $m = (get-date).Month; $y = (get-date).Year; $cnt = (gci <<<< \\[server ip]\c$\Temp\success\ | where-object {(($_.LastWriteTime).Day -eq $d) -and (($_.LastWriteTime).Month -eq $m) -and (($_.LastWriteTime).Year -eq $y)}).Count; Write-Host 'Statistic: ' $cnt; if ($cnt -eq 4) { exit(0) } else { exit(1) }
+ CategoryInfo : ObjectNotFound: (\\[server ip]\c$\Temp\success\:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
End PowerShell Execute Result =============================
The credentials being used are the same for both the monitor and for the test shell run I did on the poller, and they have the necessary permission to access the folder. The folder does, in fact, exist. Execution mode is set to Local Host. Powershell is v2.
Anyone have any idea what might be causing this problem and how I can resolve it?