Hey there,
first a hello to everybody since I am new to this forum. Secondly: I am trying to run a short powershell command from Zabbix for a Windows Server 2012 R2 Standard host. As far as I know it is powershell v1.0. The command is
<code> UserParameter=backups.db-zip,powershell.exe -NoProfile -Command {(Get-ChildItem C: | ForEach-Object { if( $_.Name -eq 'filename' ) { ((Get-Date)-$_.LastWriteTime).ToString('dd')}else{continue} } } </code>
It is meant to check a certain directory for the newly created file with <filename>. If you try the command you might have to replace the filename in the command with an actual file.
Now the problem:
The command works from either CMD or Powershell on the windows host locally. When I run it through Zabbix it throws weired errors. Something like: "ForEach-Object has not been found...". I have tried to escape the "|" with "^|", tried to replace ForEach-Object with a foreach{...\ }-loop but still get errors. Any hints on how the interpreter works? Is it using CMD/Powershell? What's going on here?
Thank you guys
Marius
first a hello to everybody since I am new to this forum. Secondly: I am trying to run a short powershell command from Zabbix for a Windows Server 2012 R2 Standard host. As far as I know it is powershell v1.0. The command is
<code> UserParameter=backups.db-zip,powershell.exe -NoProfile -Command {(Get-ChildItem C: | ForEach-Object { if( $_.Name -eq 'filename' ) { ((Get-Date)-$_.LastWriteTime).ToString('dd')}else{continue} } } </code>
It is meant to check a certain directory for the newly created file with <filename>. If you try the command you might have to replace the filename in the command with an actual file.
Now the problem:
The command works from either CMD or Powershell on the windows host locally. When I run it through Zabbix it throws weired errors. Something like: "ForEach-Object has not been found...". I have tried to escape the "|" with "^|", tried to replace ForEach-Object with a foreach{...\ }-loop but still get errors. Any hints on how the interpreter works? Is it using CMD/Powershell? What's going on here?
Thank you guys
Marius