PowerShell script exchange
Post Reply
EcoboostPerformance
Enthusiast
Posts: 27
Liked: 2 times
Joined: May 05, 2020 5:50 pm
Full Name: Ryan
Contact:

Get a list of all proxy servers for a VBR

Post by EcoboostPerformance »

I'm trying to generate a list of all proxy servers attached to veeam but I'm running into some issues.

There doesn't seam to be a command to `Get-VBRproxies` for a given server. I just want to list out all of the proxy information like it is on the backup proxies tab inside of the VBR software. So VMWare, Agent, HyperV, and CDP Proxies. So far as i can tell theres not a command-let to grab agent proxies but rather i have to query it by the individual job. This is what i have so far...

Code: Select all

 Import-Module Veeam.Backup.PowerShell | Out-Null
    Write-Host("")
    Connect-VBRServer -erroraction 'silentlycontinue'
    Write-Host("Getting VBR Vi Proxies")
    Get-VBRViProxy
    Write-Host("Getting VBR Hv Proxies")
    Get-VBRHvProxy
    Write-Host("Getting VBR Vmware CDP Proxies")
    Get-VBRCDPProxy
    Write-Host("Getting VBR Job Proxies")
    $jobs = Get-VBRJob
    foreach($j in $jobs){
    Get-VBRJobProxy -Job $j
    }
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Get a list of all proxy servers for a VBR

Post by ronnmartin61 » 1 person likes this post

I believe the cmdlet you're looking for is Get-VBRComputerFileProxyServer
EcoboostPerformance
Enthusiast
Posts: 27
Liked: 2 times
Joined: May 05, 2020 5:50 pm
Full Name: Ryan
Contact:

Re: Get a list of all proxy servers for a VBR

Post by EcoboostPerformance »

So that returns what im looking for as....

Code: Select all

PSComputerName       : vbrhost.network.local
RunspaceId           : acc70dfa-b377-43da-8ae0-206af2c3807e
Id                   : 50cbf6452-129e-482a-9297-d67e5bb1fb1f
Description          : Created by Veeam Backup & Replication
Server               : Veeam.Backup.Core.Common.CHost
ConcurrentTaskNumber : 2
But the doc on it really needs to be updated....

https://helpcenter.veeam.com/docs/backu ... ml?ver=110


As it says it will return the following...

Code: Select all

Get-VBRComputerFileProxyServer

Id                            Description                   Server                                 ConcurrentTaskNumber

--                            -----------                   ------                                 --------------------

2df7b4a9-e230-4bc7-97a6-db... Created by Veeam Backup & ... Veeam.Backup.Core.Common.C...                             2

5a7c25b9-87cb-41e3-bb1b-81... Created by Powershell at 8... Veeam.Backup.Core.Common.C...  
Why is the fact that it returns the PSCompterName completely omitted?
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Get a list of all proxy servers for a VBR

Post by ronnmartin61 »

Interesting. On both my v11 (11.0.1.1261) and beta2 v12 (12.0.0.817) I'm not seeing PSComputerName returned. Had to track down the name via Get-VBRServer like -

Code: Select all

$fpSvr = Get-VBRComputerFileProxyServer
$svr = Get-VBRserver | Where-Object {$_.Id -eq $fpSvr.Server.ToString()}
EcoboostPerformance
Enthusiast
Posts: 27
Liked: 2 times
Joined: May 05, 2020 5:50 pm
Full Name: Ryan
Contact:

Re: Get a list of all proxy servers for a VBR

Post by EcoboostPerformance »

Also that doesnt return the agent proxy information now that I am looking deeper into it...

Code: Select all

 

PSComputerName       : ito095665.domain.local.com
RunspaceId           : 0e1df007-bcf5-42e2-983d-21b0925a2ad5
Id                   : 233c90e2-eb62-46f8-b139-2ead6859be0e
Description          : Created by *******\********* at 12/21/2021 10:23 AM.
Server               : Veeam.Backup.Core.Common.CHost
ConcurrentTaskNumber : 24

PSComputerName       : ito095665.domain.local.com
RunspaceId           : 0e1df007-bcf5-42e2-983d-21b0925a2ad5
Id                   : 50cbf622-129e-482a-9197-d67e5bb1fb1f
Description          : Created by Veeam Backup & Replication
Server               : Veeam.Backup.Core.Common.CHost
ConcurrentTaskNumber : 20 
vs on the web interface
Image

If you look you will see that ito095666 is the actual Computer name for the proxy.....
EcoboostPerformance
Enthusiast
Posts: 27
Liked: 2 times
Joined: May 05, 2020 5:50 pm
Full Name: Ryan
Contact:

Re: Get a list of all proxy servers for a VBR

Post by EcoboostPerformance »

Sorry this could be due to the fact that I'm connecting to multiple sessions.... Why do i have to do something so arbitrary as

Code: Select all

$fpSvr = Get-VBRComputerFileProxyServer
$svr = Get-VBRserver | Where-Object {$_.Id -eq $fpSvr.Server.ToString()}
To get the server name of the proxy don't you think thats a bit convoluted?

If there are multiple servers which there likely are with proxies, I would have to make another custom object and dump this to a table. This should definitely be improved...
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Get a list of all proxy servers for a VBR

Post by ronnmartin61 »

Yes I agree that it would be handier if Get-VBRComputerFileProxyServer returned the friendly name as well as the hostname but if memory serves they're the same value for all manually added proxies
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get a list of all proxy servers for a VBR

Post by david.domask »

Hi all,

@EcoboostPerformance, do I get it right you just want the Server output from Get-VBRComputerFileProxy to return a friendly name in the output?

Looks like it returns a CHost Object, and the Name property has what you want, no?

Code: Select all

PS C:\Users\Administrator> $fsprox.Server.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    CHost                                    System.Object


PS C:\Users\Administrator> $fsprox.Server.Name
ddom-veeam-rb4.some.fdqn
Or am I missing what you're going for?

TBH I'm not sure why they return a CHost object here, but I can think of some reasons I might want that in a script to avoid having to do another Get-VBRServer lookup and just have the CHost right there, as the Get-VBRServer lookup can be expensive in larger environments.
David Domask | Product Management: Principal Analyst
EcoboostPerformance
Enthusiast
Posts: 27
Liked: 2 times
Joined: May 05, 2020 5:50 pm
Full Name: Ryan
Contact:

Re: Get a list of all proxy servers for a VBR

Post by EcoboostPerformance »

I Just think it would be much simpler if it just returned the proxy server information and all the values associated with it. Its something that I can get in 2 clicks in the web interface which makes me think for the sake of automation it would be much easier. In fact its much easier just to grab this information straight from the actual veeam db itself.

Code: Select all

<#      PROXY Server Finder 9000
    This script will return text files of proxy servers found from a list of VBRs Assigned to a variable.
    unable to find proxies for VBRS using local SQL express databases.
    MUST BE RAN WITH A SERVICE ACCOUNT 
#>
#newline variable
$OFS = "`n"
#path to log file
$fileName = 'C:\Scripts\results\proxies.txt'
#path to another log file lol
$filePathList = 'C:\Scripts\results\proxielist.txt'
#registry path
$VeeamRegPath = 'HKLM:\SOFTWARE\Veeam\Veeam Backup and Replication\'
#list of VBRS
$VBRServers =
"vbr1.contoso.local",
"vbr2.contoso.local"
#If log file already exists, delete it.
if (test-path -Path $fileName) { 
  Remove-Item -Path $fileName
}
if (test-path -Path $filePathList) { 
  Remove-Item -Path $filePathList
}
#iterate thru each server in list
ForEach ($VBR in $VBRServers) {
  #isettting our variables to null so they are empty at the start of each loop
  $results = $null
  $SQLServerName = $null
  $SQLDatabaseName = $null
  $serviceCheck = $null
  $sesh = $null
  #create ps session with server
  $sesh = New-PSSession -ComputerName $VBR -ErrorAction SilentlyContinue
  # if no connection can be made, move on to next server
  if ($null -eq $sesh) {
    write-host "Unable to create session with $VBR, moving on." -ForegroundColor Yellow
    continue
  }
  #check to see if veeam is installed, if not move on to next server
  $serviceCheck = Invoke-Command -Session $sesh -ScriptBlock { get-service -DisplayName "veeam backup service" -ErrorAction SilentlyContinue }
  if ($null -eq $serviceCheck) {
    $outString = "$VBR does not have Veeam installed.." 
    Write-Host $outString -ForegroundColor Magenta
    Add-Content -Value $outString -Path $fileName
    Add-Content -Value $OFS -Path $fileName
    continue 
  } else {
    write-host "$VBR has veeam installed." -ForegroundColor Cyan
  }
  #grab SQL servers name from VBR servers registry
  $SQLServerName = Invoke-Command -Session $sesh -ScriptBlock {
    Get-ItemPropertyValue -path $VeeamRegPath -Name SqlServerName } -ErrorAction Ignore
  #if there is no entry for sql server, probable postgresql is being used, move on to next server
  if ($null -eq $SQLServerName) {
    $outString = "$VBR has no SQL installation, possible Postgresql"
    write-host $outString -ForegroundColor Magenta
    Add-Content -Value $outString -Path $fileName
    Add-Content -Value $OFS -Path $fileName
    continue
  }
  <#test for SQL express.. if the sql servers name does not have any of the following domain names, than its the VBR itself
    and does not have the domain name attached to the end.move on to next server #>
  if ($SQLServerName -notlike "*.dev.contoso.local" -and $SQLServerName -notlike "*.test.contoso.local" -and $SQLServerName -notlike "*.lab.contoso.local" -and $SQLServerName -notlike "*.preprod.contoso.local") {
    $Outstring = "$VBR is using SQL Express, unable to pull proxies."
    Write-Host $outString -ForegroundColor Magenta
    Add-Content -value $outString -Path $fileName
    Add-Content -Value $OFS -Path $fileName
    continue
  }
  #Grab database name from VBR server registry
  $SQLDatabaseName = Invoke-Command -Session $sesh -ScriptBlock {
    Get-ItemPropertyValue -path $VeeamRegPath -Name SqlDatabaseName } 
  #query string
  $query = "SELECT [name],[type] FROM [dbo].[BackupProxies] where type = 6 and name NOT LIKE 'Backup Proxy' or type = 0 AND name NOT LIKE 'VMware Backup Proxy'"
  #return results of query on sql server/database
  $results = Invoke-Sqlcmd  -ServerInstance "$SQLServerName" -Database "$SQLDatabaseName" -Query "$Query" 
  #if something was returned, write to log file. 
  if ($results) {
    $outString = "VBR server: $VBR. Proxies Below.."
    Write-Host "Writing Proxies to text file for $VBR..." -ForegroundColor Green
    add-content -Value $results.name -Path $filePathList
    Add-Content -Value $outString -Path $fileName
    add-content -Value $results.name -Path $fileName
    add-content -Value $OFS -Path $fileName
  } else {
    #if nothing was return, this probably means there is no standalone dedicated proxies.
    $outstring = "$VBR Has no standalone proxies."
    Write-Host $outString -ForegroundColor Magenta
    Add-Content -Value $outString -Path $fileName
    Add-Content -Value $OFS -Path $fileName
  }
}
#remove all open ps sessions
Get-PSSession | Remove-PSSession
EcoboostPerformance
Enthusiast
Posts: 27
Liked: 2 times
Joined: May 05, 2020 5:50 pm
Full Name: Ryan
Contact:

Re: Get a list of all proxy servers for a VBR

Post by EcoboostPerformance »

david.domask wrote: Nov 30, 2022 10:56 am Hi all,

@EcoboostPerformance, do I get it right you just want the Server output from Get-VBRComputerFileProxy to return a friendly name in the output?

Looks like it returns a CHost Object, and the Name property has what you want, no?

Code: Select all

PS C:\Users\Administrator> $fsprox.Server.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    CHost                                    System.Object


PS C:\Users\Administrator> $fsprox.Server.Name
ddom-veeam-rb4.some.fdqn
Or am I missing what you're going for?

TBH I'm not sure why they return a CHost object here, but I can think of some reasons I might want that in a script to avoid having to do another Get-VBRServer lookup and just have the CHost right there, as the Get-VBRServer lookup can be expensive in larger environments.

Can you provide the entire script that you used? I had to go about it in another way to get it to work like i wanted it to.
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get a list of all proxy servers for a VBR

Post by david.domask »

Hi!

All I did was Get-VBRComputerFileProxy and save it to the $fsprox variable. :)

Then the resulting object has a property "Server" that is a CHost object with the Name property you seek
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests