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

Parameters PowerShell Select

Post by acepero » Feb 14, 2020 11:11 am

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 Software
Posts: 138
Liked: 35 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Parameters PowerShell Select

Post by jhoughes » Feb 14, 2020 11:16 am

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 | @AustinVMUG & @ATXPowerShell leader | VMUG US South Regional Champion | VMware vExpert | Cisco Champion

acepero
Novice
Posts: 5
Liked: never
Joined: Feb 10, 2020 7:46 am
Full Name: Alberto Cepero
Contact:

Re: Parameters PowerShell Select

Post by acepero » Feb 14, 2020 11:38 am

I don't know very well what I mean, can you give an example please

jhoughes
Veeam Software
Posts: 138
Liked: 35 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Parameters PowerShell Select

Post by jhoughes » Feb 14, 2020 11:52 am

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 | @AustinVMUG & @ATXPowerShell leader | VMUG US South Regional Champion | VMware vExpert | Cisco Champion

acepero
Novice
Posts: 5
Liked: never
Joined: Feb 10, 2020 7:46 am
Full Name: Alberto Cepero
Contact:

Re: Parameters PowerShell Select

Post by acepero » Feb 14, 2020 12:11 pm

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: 144
Liked: 46 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Parameters PowerShell Select

Post by oleg.feoktistov » Feb 14, 2020 12:32 pm

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: 144
Liked: 46 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Parameters PowerShell Select

Post by oleg.feoktistov » Feb 14, 2020 12:45 pm 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
Veeam Software
Posts: 186
Liked: 92 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Kentucky, USA
Contact:

Re: Parameters PowerShell Select

Post by chris.arceneaux » Feb 14, 2020 1:36 pm

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 4 guests