1

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 : 

2 Answers 2

1

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]}}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help, and for the explanation, since it has helped me understand how it works!
0

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.

6 Comments

Please edit your question to show us the change you've made.
OK, i did changes
I wanted to see your updated script actually. But perhaps we wrongly assumed you'd added the [0] to this and it wasn't working $_.PartialPath[0]. In which case try this $_.PartialPath[0].split('.')[0].
Thanks. I'm still a bit confused as to what you are executing when you actually get the name of the VM returned. Is it the code you put at the top of your question or not?
That is, first I show how the name shows me with the code of my question, and then I show what it shows when I modify my code with your help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.