Reputation: 137
I have a simple script, which I want to show me some results, but in the name of the virtual machine, I only want to the first point, everything else is left over because it generates a lot of noise.
$today = (get-date).Date
$backup = Get-VBRBackup | where {$_.info.jobname -eq "A. ProduccionInterna.Infraestructura Backup Copy"}
if ($backup) {
$backup.GetAllStorages() | where {$_.CreationTime.Date -eq $today} | select @{Name="Nombre de la VM"; Expression={$_.PartialPath[0]}}, @{Name="Size VM"; Expression={$_.Stats.BackupSize/1GB}} , @{Name="Deduplicacion"; Expression={$Session.BackupStats.DedupRatio/10}} , @{Name="Compress Ratio"; Expression={$Session.BackupStats.CompressRatio/10}} , @{Name="Fecha"; Expression={(get-date).Date}}
}
Result:
f5downinxn.vm-37087D2020-02-21T030000_B816.vib
But, I wont:
f5downinxn
The chain that entered does not seem to work.
[0]
I have also tried with
(".")[1]
EDIT
With my code:
Nombre de la VM : f5downinxn.vm-37087D2020-02-21T030000_B816.vib
With changes:
Code
$today = (get-date).Date
$backup = Get-VBRBackup | where {$_.info.jobname -eq "A. ProduccionInterna.Infraestructura Backup Copy"}
if ($backup) {
$backup.GetAllStorages() | where {$_.CreationTime.Date -eq $today} | select @{Name="Nombre de la VM"; Expression={$_.PartialPath[0].split('.')[0]}}, @{Name="Size VM"; Expression={$_.Stats.BackupSize/1GB}} , @{Name="Deduplicacion"; Expression={$Session.BackupStats.DedupRatio/10}} , @{Name="Compress Ratio"; Expression={$Session.BackupStats.CompressRatio/10}} , @{Name="Fecha"; Expression={(get-date).Date}}
}
Nombre de la VM :
Upvotes: 1
Views: 95
Reputation: 25031
The .PartialPath
property is a Veeam.Backup.Common.CPartialPath
object. The tabular output is performing some string conversion magic, but the underlying object is not a string. However, Veeam.Backup.Common.CPartialPath
has a ToString()
override method that should make this task easier.
Select @{Name="Nombre de la VM"; Expression={$_.PartialPath.ToString().Split('.')[0]}}
Upvotes: 1
Reputation: 23405
Try doing this in your Select-Object
where you're currently returning just $_.PartialPath
as the VM name:
$_.PartialPath.Split('.')[0]
This should split the contents of the PartialPath
property on the .
character into an array of strings and then return you the first one.
Note that you may get errors if PartialPath
ever contains a string without a .
as the split would then not generate an array and the use of [0]
would be invalid.
Upvotes: 0