PowerShell script exchange
Post Reply
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Client OS Type Script

Post by ebcstanger »

I have been looking all over on how I can get the client os type by using a powershell script and have not found it. I would like to produce something on the lines of what you see in the inventory section which shows the guest os. I know that I can get it with doing SQL calls but would rather use powershell.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

Check this example:

Code: Select all

Asnp VeeamPSSnapin
$VM = Find-VBRViEntity -Server (Get-VBRServer -name "Name of your ESXi or vCenter server") | where {$_.name -eq "Name of your VM"}
$VM.GuestInfo.GetGuestOsName()
Thanks!
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Re: Client OS Type Script

Post by ebcstanger »

When I run this script it only returns my ESX host and the veeam server os type and not all of the guest os that I am protecting.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

Yeah, because it's the example for single VM, to get the information regarding all VMs you need to create something like this:

Code: Select all

Asnp VeeamPSSnapin
$VMs = Find-VBRViEntity -Server (Get-VBRServer -name "Name of your ESXi or vCenter server") | where {$_.type -eq "VM"}
Foreach ($VM in $VMs)
{
$VM | select name, {$_.GuestInfo.GetGuestOsName()}
}
Thanks!
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Re: Client OS Type Script

Post by ebcstanger »

That worked great, another question. I am new to the powershell side with veeam and found a script that i have been using for reporting on backups and wanted to know how i can merge what you provided into the following script.

Code: Select all

$allJobs | ?{$_.JobType -eq "Backup"} | %{
    
    $job = $_
    $JobName = $_.Name
    $Backup = Get-VBRBackup -Name $JobName
    $lastsession = $job.FindLastSession()
    $Session = $job.FindLastSession()
    foreach($tasksession in $lastsession.GetTaskSessions()) {
    $PointsOnDisk = (get-vbrbackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count 
    $BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
    $BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
    $RepositoryPath = $Backup.Info.DirPath.ToString()
    $LastBackupStart = $Session.CreationTime
    $LastResult = $job.GetLastResult()    
    }
      
      $_ | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"} | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}} | Sort -Property Job, Name 
} 
Output: Which i would like to add the OS Type too

Code: Select all

Job                 : Local Disk
Name                : AUSDPSFS3
Size                : 50.0 GB
PointsOnDisk        : 3
LastResult          : Success
LastBackupStart     : 8/19/2019 9:10:47 AM
LastBackupTotalSize : 50
LastBackupSize      : 2
RepositoryPath      : F:\Local Disk
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

Not sure whether I follow you on that - you want to add the information regarding the operating systems protected to the provided output? Thanks!
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Re: Client OS Type Script

Post by ebcstanger »

correct
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

Don't have a console to confirm the script, but I think you will need something like this:

Code: Select all

$Server = Get-VBRServer -name "Name of your vCenter or ESXi host" 
$allJobs | ?{$_.JobType -eq "Backup"} | %{
    
    $job = $_
    $JobName = $_.Name
    $Backup = Get-VBRBackup -Name $JobName
    $lastsession = $job.FindLastSession()
    $Session = $job.FindLastSession()
    foreach($tasksession in $lastsession.GetTaskSessions()) {
    $PointsOnDisk = (get-vbrbackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count 
    $BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
    $BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
    $RepositoryPath = $Backup.Info.DirPath.ToString()
    $LastBackupStart = $Session.CreationTime
    $LastResult = $job.GetLastResult()    
    }
    foreach  ($Object in ($job | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"}))
    { 
      $Object | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}}, @{ L="OSType"; E={(Find-VBRViEntity -Server $Server | where {$_.name -like $Object.GetObject().info.displayname}).GuestInfo.GetGuestOsName()}}| Sort -Property Job, Name
    }
} 
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Re: Client OS Type Script

Post by ebcstanger »

Returns a blank OS type

Job : Local Disk
Name : AUSDPSFS3
Size : 50.0 GB
PointsOnDisk : 3
LastResult : Success
LastBackupStart : 8/19/2019 9:10:47 AM
LastBackupTotalSize : 50
LastBackupSize : 2
RepositoryPath : F:\Local Disk
OSType :
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

For some VMs OSType is not collected, you can confirm that by going to Inventory node and checking VM in question (Guest OS column). Thanks!
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Re: Client OS Type Script

Post by ebcstanger »

With your original script it shows the OS for the server that i listed above.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

And you have added the first line where $Server variable is assigned?

The script works in my environment, so, you can play with this part a bit to find the issue:

Code: Select all

foreach  ($Object in ($job | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"}))
{ 
    $Object | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}}, @{ L="OSType"; E={(Find-VBRViEntity -Server $Server | where {$_.name -like $Object.GetObject().info.displayname}).GuestInfo.GetGuestOsName()}}| Sort -Property Job, Name
}
Thanks!
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Re: Client OS Type Script

Post by ebcstanger »

That worked, i had a setting wrong in my script. :( I added an export to the end of the $Object statement trying to export out to a csv file and its only grabbing the last entry of the output. Do you know why that would be?

Code: Select all

$Object | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}}, @{ L="OSType"; E={(Find-VBRViEntity -Server $Server | where {$_.name -like $Object.GetObject().info.displayname}).GuestInfo.GetGuestOsName()}}| Sort -Property Job, Name | Export-CSV -NoTypeInformation  -Path "C:\JobInfo.csv"
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

Not an expert in this area, but you can try a slightly different approach:

Code: Select all

$Server = Get-VBRServer -name "Name of your vCenter or ESXi host" 
$resultsarray=@()
$allJobs | ?{$_.JobType -eq "Backup"} | %{
    $job = $_
    $JobName = $_.Name
    $Backup = Get-VBRBackup -Name $JobName
    $lastsession = $job.FindLastSession()
    $Session = $job.FindLastSession()
    foreach($tasksession in $lastsession.GetTaskSessions()) {
    $PointsOnDisk = (get-vbrbackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count 
    $BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
    $BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
    $RepositoryPath = $Backup.Info.DirPath.ToString()
    $LastBackupStart = $Session.CreationTime
    $LastResult = $job.GetLastResult()    
    }
    foreach  ($Object in ($job | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"}))
    { 
        $backupObject = New-Object PSObject
        $backupObject | Add-Member -MemberType NoteProperty -name "Job" -Value $JobName
        $backupObject | Add-Member -MemberType NoteProperty -name "Size" -Value $Object.ApproxSizeString
        $backupObject | Add-Member -MemberType NoteProperty -name "PointsOnDisk" -Value $PointsOnDisk
        $backupObject | Add-Member -MemberType NoteProperty -name "LastResult" -Value $LastResult
        $backupObject | Add-Member -MemberType NoteProperty -name "LastBackupStart" -Value $LastBackupStart
        $backupObject | Add-Member -MemberType NoteProperty -name "LastBackupTotalSize" -Value $BackupTotalSize
        $backupObject | Add-Member -MemberType NoteProperty -name "LastBackupSize" -Value $BackupSize    
        $backupObject | Add-Member -MemberType NoteProperty -name "RepositoryPath" -Value $RepositoryPath
        $backupObject | Add-Member -MemberType NoteProperty -name "OSType" -Value ((Find-VBRViEntity -Server $Server | where {$_.name -like $Object.GetObject().info.displayname}).GuestInfo.GetGuestOsName())
        $resultsarray += $backupObject
    }
} 
$resultsarray | Export-CSV -NoTypeInformation  -Path "C:\JobInfo.csv"
If this doesn't help, kindly, reach general PS community for questions concerned with non Veeam specific PS functions.

Thanks!
ebcstanger
Novice
Posts: 8
Liked: never
Joined: Aug 20, 2019 2:39 pm
Full Name: Pat Harris
Contact:

Re: Client OS Type Script

Post by ebcstanger »

I added another entry to collect the Server name and looking into why the OSType is returning an error stating that you can not call a method
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Client OS Type Script

Post by veremin »

Seems like an OSType cannot be collected for a particular VM as the result the error is generated.

Anyway, if the previous example works for you, you just need to find a way to solve the csv export issue.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests