Forum Discussion

Kelemvor's avatar
Kelemvor
Icon for Expert rankExpert
26 days ago

How to create a DataSource to return 2 values via PowerShell?

Hi,

I'm trying to write a DS to return how many Hyper-V Snapshots I have that are more than 3 days old.  The script works but I'm having trouble returning the data.

Here's the script and the output it's showing:

What I want to get is the number 1 in the result column and the name of the VMs with Old Snapshots in the OldSnapshots column.  I've tried various options for the Interpret output with and other settings but can't get it to work.

Sometimes it looks like it works, but still shows an error.  Then it will have NoData in the Raw Data area.  Is it because it's text and not a number?

I'm just spinning my wheels at this point so any help would be great.

Thanks.

  • Yeah, Datapoints can only be numbers. You can't have text in it.

    For the case where you want to report which VMs have old snapshots. You can might be able to make the VMs into instances and each report it's snapshot age.

    I also don't suggest you code thresholds into the code directly, just report the age in hr (or min or days) and use LM to set thresholds. That way you can have overrides and exceptions.

     

    • Kelemvor's avatar
      Kelemvor
      Icon for Expert rankExpert

      Yeah.  I don't know how I'd code that...  Of course LM has an official one for VMWare snapshots, but not for Hyper-V Snapshots.

      At least this one will give me something to go off of for now.  I'll see if we can figure something else out down the road.

  • How does the data look? Would you be able to create an instance per VM then do math on when the last snapshot was taken compared to the time of poll? Then you would have something like

    SERVERA - 27 (Hours ago)

    • Kelemvor's avatar
      Kelemvor
      Icon for Expert rankExpert

      I'm sure that Could be done.  But I have no idea how to do it.  ;)  The one I have now works, even though it doesn't work 100%.  It works enough to throw an alert if a Snapshot age goes over 3 days.  Then I can just go look at the error to see which VM it is.

      I don't know how to create DataPoints.  The only reason I got as far as I did is I was copying a different one and tweaking it to try to get what I needed.   Since VMs are stored on the HPV Hosts, I thought the instances would be the Hosts and then it'd be able to put the VMName in the Raw Data.  But since it's Text, I guess that won't work.