-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Client OS Type Script
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.
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
Check this example:
Thanks!
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()
-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Re: Client OS Type Script
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.
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
Yeah, because it's the example for single VM, to get the information regarding all VMs you need to create something like this:
Thanks!
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()}
}
-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Re: Client OS Type Script
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.
Output: Which i would like to add the OS Type too
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
}
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
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
Not sure whether I follow you on that - you want to add the information regarding the operating systems protected to the provided output? Thanks!
-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Re: Client OS Type Script
correct
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
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
}
}
-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Re: Client OS Type Script
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 :
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 :
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
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!
-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Re: Client OS Type Script
With your original script it shows the OS for the server that i listed above.
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
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:
Thanks!
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
}
-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Re: Client OS Type Script
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"
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
Not an expert in this area, but you can try a slightly different approach:
If this doesn't help, kindly, reach general PS community for questions concerned with non Veeam specific PS functions.
Thanks!
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"
Thanks!
-
- Novice
- Posts: 8
- Liked: never
- Joined: Aug 20, 2019 2:39 pm
- Full Name: Pat Harris
- Contact:
Re: Client OS Type Script
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
-
- Product Manager
- Posts: 20413
- Liked: 2301 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Client OS Type Script
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!
Anyway, if the previous example works for you, you just need to find a way to solve the csv export issue.
Thanks!
Who is online
Users browsing this forum: No registered users and 14 guests