0

This is what I wrote to get output with powercli;

Get-VM -name SERVERX | Get-Annotation -CustomAttribute "Last EMC vProxy Backup"|select @{N='VM';E={$_.AnnotatedEntity}},Value

This is the output

VM       Value                                                                                                                                                                                
--       -----                                                                                                                                                                                
SERVERX  Backup Server=networker01, Policy=vmbackup, Workflow=Linux_Test_Production, Action=Linux_Test_Production, JobId=1039978, StartTime=2018-10-31T00:00:27Z, EndTime=2018-10-31T00:12:45Z
SERVERX1 Backup Server=networker01, Policy=vmbackup, Workflow=Linux_Test_Production, Action=Linux_Test_Production, JobId=1226232, StartTime=2018-12-06T00:00:29Z, EndTime=2018-12-06T00:0...
SERVERX2 Backup Server=networker01, Policy=vmbackup, Workflow=Linux_Test_Production, Action=Linux_Test_Production, JobId=1226239, StartTime=2018-12-05T23:58:27Z, EndTime=2018-12-06T00:0...

But I would like retrieve only "starttime" and "endtime" values

Desired output is;

 VM       Value                                                                                                                                                                                
 --       -----      
 SERVERX  StartTime=2018-10-31T00:00:27Z, EndTime=2018-10-31T00:12:45Z
 SERVERX1 StartTime=2018-12-06T00:00:29Z, EndTime=2018-1206T00:11:14Z
 SERVERX2 StartTime=2018-12-05T23:58:27Z, EndTime=2018-12-06T00:11:20Z

How can I get this output?

1010111100011
  • 83
  • 1
  • 3
  • 9

1 Answers1

0

This would be better suited in Powershell forum as this is just data manipulation.

Providing your output is always the same number of commas then

$myannotation = Get-VM -name SERVERX | Get-Annotation -CustomAttribute "Last EMC 
vProxy Backup"|select @{N='VM';E={$_.AnnotatedEntity}},Value
$table1 = @()
foreach($a in $myannotation)
    $splitter = $a.value -split ','
    $splitbackupstart = $splitter[5]
    $splitbackupend = $splitter[6]
    $row = '' | select vmname, backupstart, backupend
    $row.vmname = $a.AnnotatedEntity # or .vm would have to try
    $row.backupstart = $splitbackupstart 
    $row.backupend= $splitbackupend 
    $table1 += $row
}
$table1

Untested. If you format of the string is going to change over time then a regex to search for starttime will be better.

user3520245
  • 1,016
  • 1
  • 8
  • 18