Good afternoon,
I have created this PowerShell script to monitor if a remote server has or has not Shadow Copies on the system.
Function GetShadowCount
{
Get-WmiObject Win32_ShadowCopy -ComputerName ${IP} -Credential ${CREDENTIAL} | Select Count;
}
Function OnlyTrue
{
if(GetShadowCount)
{
Write-Host Statistic: 1;
Write-Host Message: "The server has Shadow Copies";
exit 1;
}
Else
{
Write-Host Statistic: 0;
Write-Host Message: "The server has no Shadow Copies";
exit 0;
}
}
OnlyTrue
I know there is no need to use functions, but this is only one of the many ways I tried to make it work.
If I run the code directly on ISE, it works perfectly. It only does not work on PowerShell SAM Monitor.
If I replace the command "Get-WmiObject Win32_ShadowCopy -ComputerName ${IP} -Credential ${CREDENTIAL} | Select Count;" by "Get-WmiObject win32_process -ComputerName '${IP}' -Credential '${CREDENTIAL}';", it works on the SAM monitor normally.
It looks it's something on the WMI Object Win32_ShadowCopy that the SAM Monitor doesn't "like".
The biggest problem is that it simply does not give me any error to debug.
I'm testing it against a server which I'm sure it has Shadow Copies. As I told, the script works on ISE and it returns the Shadow Copies count.
The problem is that, as the command on function GetShadowCount does not work properly, it always goes to the ELSE clause and says there is not Shadow Copies.

Any clues?
Any suggestion is very welcome.
Thanks for reading and helping.