Hello,
I using powershell 5.
I've tried your code and it's works
$tablivemount = @()
$vm_live_mount = Invoke-RubrikRESTCall -Endpoint vmware/vm/snapshot/mount -api 1 -Method GET
if ($vm_live_mount.total -eq 0){
$tablivemount += [PSCustomObject]@{
DestinationId = "Pas de migration en attente"
SourceId = ""
Datedemontage = ""
Datedusnapshot= ""}
}
Else{
forEach($LiveMount in $vm_live_mount.data){
$tablivemount += [PSCustomObject]@{
DestinationId = ($ALLmanagedvm.data |Where-Object {$_.id -eq $LiveMount.VmId}).name
SourceId = ($ALLmanagedvm.data |Where-Object {$_.id -eq $LiveMount.mountedVmId}).name
Datedemontage = ([datetime]$LiveMount.mountTimestamp).ToLocalTime().ToString("d/MM/y HH:mm:ss")
Datedusnapshot= ([datetime]$LiveMount.snapshotDate).ToLocalTime().ToString("d/MM/y HH:mm:ss")
}
}
}
$tablivemount
The return is :
$tablivemount
@{DestinationId=aaaaa; SourceId=aaaaa; Datedemontage=18/02/22 09:18:37; Datedusnapshot=15/02/22 19:30:10}@{DestinationId=aaaaa; SourceId=bbbbb; Datedemontage=18/02/22 09:19:00; Datedusnapshot=14/02/22 19:33:27}
How i can exploit with Format Table ?
$tablivemount | Select-object DestinationId, SourceId | FT
DestinationId SourceId
------------- --------
$ALLmanagedvm is declare on another part of this script.
Just for information I ve also tried my script with -passthru and it return that:
...
$tablivemount_temp = @()
$tablivemount_temp = New-Object psobject
$tablivemount_temp | Add-Member -NotePropertyName "DestinationId" -NotePropertyValue $DestinationId -PassThru
$tablivemount_temp | Add-Member -NotePropertyName "SourceId" -NotePropertyValue $SourceId -PassThru
$tablivemount_temp | Add-Member -NotePropertyName "Datedemontage" -NotePropertyValue $mountTimestamp
$tablivemount_temp | Add-Member -NotePropertyName "Datedusnapshot" -NotePropertyValue $snapshotDate
$tablivemount +=$tablivemount_temp}
}
$tablivemount | Select-Object DestinationId, SourceId, Datedemontage, Datedusnapshot
it's return
$tablivemount | Select-Object DestinationId, SourceId, Datedemontage, Datedusnapshot
Récupération des Instant Recovery VM en cours
DestinationId
-------------
aaaaaa
aaaaaa
If you can explain me what's wrong ?