Reputation: 119
I have a Powershell command that for automation purposes in our monitoring system, I'm trying to write in one line.
Basically, we're checking multiple Hyper-V virtual machines to make sure they are replicating properly. The way we're doing this is checking the last replication date/time and comparing it to the current date/time. Here's the one-liner I have for checking one machine.
(new-timespan -start(get-vm termserv002| Measure-VMReplication | select -expand lastreplicationtime)).totalminutes
This works perfectly. However, we'd like to check ALL of the VMs on this Hyper-V box. I can do this without running the new-timespan by running this command -
get-vm | where {$_.replicationstate -ne "Disabled"} | Measure-VMReplication | select vmname, lastreplicationtime
This gives me every VM on the box and its last replication time.
Ultimately, what I'd like for output is the VMName and LastReplicationTime in minutes from current date/time. If I can do this on one line, homerun!
Any suggestions? No matter how I try to meld the two together, I just can't seem to get the syntax right (Or it's not possible.)
Upvotes: 1
Views: 134
Reputation: 60976
I can't test it but give this a try:
get-vm | where {$_.replicationstate -ne "Disabled"} | Measure-VMReplication |
select vmname, @{n="LastReplicationTime";e={ (new-timespan -start ($_.lastreplicationtime) -end (get-date)).TotalMinutes }}
Upvotes: 2