PowerShell script exchange
Post Reply
acepero
Novice
Posts: 7
Liked: never
Joined: Feb 10, 2020 7:46 am
Full Name: Alberto Cepero
Contact:

Parameters PowerShell Select

Post by acepero »

Good morning, I have the following Script:

Code: Select all

$today = (get-date).Date
$backup = Get-VBRBackup | where {$_.info.jobname -eq "Name of Backup Job"}
if ($backup) {
    $backup.GetAllStorages() | where {$_.CreationTime.Date 
    #-eq $today
    } | select {$_.PartialPath}, {$_.Stats.BackupSize/1GB}, {$_.CreationTime}
}
In the sample it shows the size of all the Backups and their date, but I would like to know how to add more data, but I cannot find any more example variables of the mode:

Code: Select all

{$_."parameter"}
Such as deduplication or compression level etc.

Thx
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Parameters PowerShell Select

Post by jhoughes »

Just pipe the results of Get-VBRBackup to Get-Member, you will see other properties that are objects with additional properties.

If you are having problems understanding this, install the PowerShell cookbook module from the PSGallery and pipe the results of Get-VBRBackup to Show-Object. That tool will give you a tree view of the properties and sub-properties.
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
acepero
Novice
Posts: 7
Liked: never
Joined: Feb 10, 2020 7:46 am
Full Name: Alberto Cepero
Contact:

Re: Parameters PowerShell Select

Post by acepero »

I don't know very well what I mean, can you give an example please
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Parameters PowerShell Select

Post by jhoughes »

Start with:

Code: Select all

Get-VBRBackup | Get-Member
This will show you the properties of the backup where you can start to look for the properties that you need

If you get stuck, you can also search the PowerShell forum for those terms for examples within other scripts to learn where to find that data within the object.
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
acepero
Novice
Posts: 7
Liked: never
Joined: Feb 10, 2020 7:46 am
Full Name: Alberto Cepero
Contact:

Re: Parameters PowerShell Select

Post by acepero »

I do

Code: Select all

Get-VBRBackup | Get-Member -MemberType "Property"
But, half of the CMDLets it shows do not work, for example:

Code: Select all

 
$today = (get-date).Date
$backup = Get-VBRBackup | where {$_.info.jobname -eq "Name"}
if ($backup) {
    $backup.GetAllStorages() | where {$_.CreationTime.Date 
    #-eq $today
    } | select {$_.PartialPath}, {$_.Stats.BackupSize/1GB}, {$_.DirPath}
}
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Parameters PowerShell Select

Post by oleg.feoktistov »

Hi Alberto,

DirPath property you added to your script is a property of CBackup object you retrieve with Get-VBRBackup cmdlet.
In your script, as soon as you call $backup.GetAllStorages(), you start to work with CStorage object, which doesn't have DirPath property.
So, you need to call DirPath on $backup variable, which contains CBackup object:

Code: Select all

$backup.GetAllStorages() | where {$_.CreationTime.Date -eq $today} | select {$_.PartialPath}, {$_.Stats.BackupSize/1GB}, {$backup.DirPath} 
Best regards,
Oleg
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Parameters PowerShell Select

Post by oleg.feoktistov » 1 person likes this post

Like Joe, I'd recommend to install Powershell Cookbook module and pipe the cmdlets you need to Show-Object to get acquainted with objects and their properties
in a more convenient way:

Code: Select all

Install-Module -Name PowerShellCookbook -RequiredVersion 1.3.5
Thanks!
chris.arceneaux
VeeaMVP
Posts: 667
Liked: 358 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Parameters PowerShell Select

Post by chris.arceneaux »

Adding to what Joe & Oleg mentioned, here's a blog article explaining in detail how to use these methods:

https://devblogs.microsoft.com/scriptin ... ow-object/
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests