PowerShell script exchange
Post Reply
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Powershell returns null when converting to json

Post by kpolsana »

Here is the powershell command we are using

Get-VBRJob -Name *

Job Name Type State Last Result Description
-------- ---- ----- ----------- -----------
AGT-001 Windows Agen... Stopped Success

When we run the above command converting to Json it returns null values please advise

Code: Select all

PS C:\> Get-VBRJob -Name * | Select-Object Name, Type, State, LastResult, Description | ConvertTo-Json
[
    {
        "Name":  "AGT-001",
        "Type":  null,
        "State":  null,
        "LastResult":  null,
        "Description":  "Created by  at 6/14/2022 4:29 PM."
    },
Please advise
Mildur
Product Manager
Posts: 8735
Liked: 2296 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Powershell returns null when converting to json

Post by Mildur »

Hi Koushik

Last State and Last Result are hidden behind methods. Those are no properties on a backup object. So we need to use the methods to see the values. The type information is stored in the property TypeToString directly.

That command should work to get a list, but it will export last result and state as numbers.

Code: Select all

Get-VBRJob -Name * | Select-Object Name, TypeToString, @{label='State' ; expression={$_.GetLastState()}}, @{label='Result' ; expression={$_.GetLastResult()}}, Description | ConvertTo-Json
I found this workaround on reddit. First convert it to CSV, then to Json. And you get the string.

Code: Select all

Get-VBRJob -Name * | Select-Object Name, TypeToString, @{label='State' ; expression={$_.GetLastState()}}, @{label='Result' ; expression={$_.GetLastResult()}}, Description | ConvertTo-CSV | ConvertFrom-Csv | ConvertTo-Json
Thanks,
Fabian
Product Management Analyst @ Veeam Software
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

Awesome that worked, thanks a lot really appreciate the help
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

So simillarly when I use the following command

Code: Select all

Get-VBRJobObject VM_001

Name                      Type       ApproxSize       Location
----                      ----       ----------       --------
BC001                  Include    40 GB

Code: Select all

Get-VBRJobobject -Job AE01BC-VM_001 | Select-Object Name, ApproxSize | ConvertTo-Json 
{
    "Name":  "BC001",
    "ApproxSize":  null
}
So when I tried to convert to csv what is typetostring @{label='approxsize' ;}
or the command should look like

Code: Select all

Get-VBRJobobject -Job VM_001 | Select-Object DisplayName, TypeToString, @{label=\'ApproxSizeString\' ; expression={$_.ApproxSizeString()}}  | ConvertTo-CSV | ConvertFrom-Csv | ConvertTo-Json


and the above is giving me an error here is full Json export

Code: Select all

"TypeDisplayName":  "Virtual Machine",
    "Filter":  null,
    "Role":  0,
    "Name":  "AE01TBI-LSBC001",
    "Type":  0,
    "Location":  
    "OrderNo":  0,
    "ApproxSizeString":  "40 GB", 
All we need is Name and ApproxSizeString
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

Code: Select all

Get-VBRInstalledLicense | Select-Object Status, ExpirationDate, Type,Edition, LicensedTo | ConvertTo-Json
{
    "Status":  1,
    "ExpirationDate":  "\/Date(1669852800000)\/",
    "Type":  3,
    "Edition":  3,
    "LicensedTo":  "Veeam Software Group GmbH"
}'

how can I get those numbers to names like below ?

Code: Select all

Status                              : Expired
ExpirationDate                      : 12/1/2022 12:00:00 AM
Type                                : Evaluation
Edition                             : EnterprisePlus
LicensedTo                          : Veeam Software Group GmbH
SocketLicenseSummary                : {Veeam.Backup.PowerShell.Infos.VBRSocketLicenseSummary}
InstanceLicenseSummary              : Veeam.Backup.PowerShell.Infos.VBRInstanceLicenseSummary
CapacityLicenseSummary              : Veeam.Backup.PowerShell.Infos.VBRCapacityLicenseSummary
SupportId                           : N/A
SupportExpirationDate               :
AutoUpdateEnabled                   : False
FreeAgentInstanceConsumptionEnabled : True
CloudConnect                        : Disabled
Mildur
Product Manager
Posts: 8735
Liked: 2296 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Powershell returns null when converting to json

Post by Mildur »

For me, the same workaround works:

Code: Select all

Get-VBRInstalledLicense | Select-Object Status, ExpirationDate, Type,Edition, LicensedTo | ConvertTo-CSV | ConvertFrom-Csv | ConvertTo-Json

{
    "Status":  "Valid",
    "ExpirationDate":  "14.11.2023 00:00:00",
    "Type":  "NFR",
    "Edition":  "EnterprisePlus",
    "LicensedTo":  "Company"
}

Or do you need to know those properties?

Code: Select all

SocketLicenseSummary                : {Veeam.Backup.PowerShell.Infos.VBRSocketLicenseSummary}
InstanceLicenseSummary              : Veeam.Backup.PowerShell.Infos.VBRInstanceLicenseSummary
CapacityLicenseSummary              : Veeam.Backup.PowerShell.Infos.VBRCapacityLicenseSummary
Product Management Analyst @ Veeam Software
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Powershell returns null when converting to json

Post by david.domask »

Sorry to jump in, but @kpolsana, I think some of your challenges with the date items are due to ConvertTo-JSON's handling of DateTime objects pre-Powershell 7:

https://learn.microsoft.com/en-us/power ... rshell-7.3
As of PowerShell 7.2, Extended Type System properties of DateTime and String objects are no longer serialized and only the simple object is converted to JSON format
For example, on Powershell 5, running the examples from Microsoft's article don't produce the same output as the article, and I'm assuming that it's due to the improvements in Powershell 7

For your test with the JobObject, it's because the property name is ApproxSizeString, not ApproxSize:

Code: Select all

PS C:\Users\Administrator> Get-VBRJobObject -Job "linux-backup" | select Name, ApproxSizeString |ConvertTo-JSON
{
    "Name":  "ddom-debian-backmeup",
    "ApproxSizeString":  "16 GB"
}
So for DateTime objects, you're going to want to probably write some function to build a PSCustomObject from the desired data, and then pass that to ConvertTo-JSON, for the others, check that you're calling the correct properties and what type the data is.
David Domask | Product Management: Principal Analyst
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

In the above similar way when running following command

Code: Select all

Get-VBRBackupRepository | select-object Name,type,Host,FreindlyPath,Description  | ConvertTo-CSV | ConvertFrom-Csv | ConvertTo-Json
I would like to only get the following out same as the running Get-VBRBackupRepository
Name, Type,Host,FriendlyPath, Description

I can see the output but the values of Host and friendly Path are empty

Code: Select all

{
        "Name":  "REPO002",
        "Type":  "",
        "Host":  "",
        "FreindlyPath":  "",
        "Description":  "Created by  at 6/14/2022 12:22 PM."
    },
Please advise
Mildur
Product Manager
Posts: 8735
Liked: 2296 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Powershell returns null when converting to json

Post by Mildur »

Hi Koushik

I just learned today that we can use .toString() to overcome the CSV workaround :)
In your example you have a typo for FreindlyPath. It should be FriendlyPath. The name of the host is a property of the Veeam.Backup.Core.Common.CHost object. So I used an expression to read the value of this property. You could also use -expandproperty to get it, but it won't work because "name" is already used in select-object.

Code: Select all

Get-VBRBackupRepository | select-object Name,
    @{Label="Type";Expression={(($_.Type).toString())}},
    @{Label="Host";Expression={(($_.Host).Name)}},
    FriendlyPath,
    Description | Convertto-Json
Best,
Fabian
Product Management Analyst @ Veeam Software
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

This is Fantastic Thanks a lot
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

When I use this command it does not return the AHV job names or AHV backups

Code: Select all

Get-VBRJob -Name * | Select-Object Name, TypeToString, @{label='State' ; expression={$_.GetLastState()}}, @{label='Result' ; expression={$_.GetLastResult()}}, Description | ConvertTo-CSV | ConvertFrom-Csv | ConvertTo-Json 
Is there any other command I have to use get the AHV backups as well
Mildur
Product Manager
Posts: 8735
Liked: 2296 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Powershell returns null when converting to json

Post by Mildur »

Hi Koushik

Unfortunately Nutanix AHV doesn't have PowerShell support.
You won't get Backup Job information per Powershell.

Best,
Fabian
Product Management Analyst @ Veeam Software
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

what is the other way to get this info other than using enterprise manager ?
Mildur
Product Manager
Posts: 8735
Liked: 2296 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Powershell returns null when converting to json

Post by Mildur »

You may try this script which uses unsupported methods to get data about Nutanix Jobs. But I cannot guarantee that it still works for V11. Also we cannot provide support for this methods.
https://github.com/VeeamHub/powershell/ ... Report.ps1

Update:
Our upcoming release of Veeam Backup for Nutanix AHV (v4) introduces a new public Rest API. You may get such job information directly per API calls from the proxy. I cannot share yet what‘s queries are available with the new API, but you can check it out as soon we have it released.

Thanks
Fabian
Product Management Analyst @ Veeam Software
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

Looks like that only works for V10
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Powershell returns null when converting to json

Post by david.domask »

@kpolsana, as in, you tested it and it did not work? Looking at the code, the only unsupported method is the call for the CBackupJobSessions .net method, and that should not have changed.

Can you run

$Nutanix_Backups = Get-VBRBackup | Where-Object { $_.TypeToString -like "Nutanix*" -AND $_.JobType -ne "VmbApiPolicyTempJob" }

Does it return your Nutanix backups?

If you do $Nutanix_backups[0].GetJob(), is anything returned?
David Domask | Product Management: Principal Analyst
kpolsana
Service Provider
Posts: 56
Liked: 2 times
Joined: Dec 10, 2021 6:35 pm
Full Name: Koushik Polsana
Contact:

Re: Powershell returns null when converting to json

Post by kpolsana »

It returns only the Nutanix agent backup(which are the VM of the Nutanix backup job) not the Nutanix backup job name
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Powershell returns null when converting to json

Post by david.domask »

@kpolsana and did you then run it with the .GetJob() method as the last line? Can you please show your console output?
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests