Get All Computer which runs Veeam Agent in the AD Domain and show the result.

  • 19 October 2023
  • 7 comments
  • 109 views

Userlevel 7
Badge +2

Hi Everyone,

 

I’m sharing this script to find where the Veeam Agent is running in the AD domain.

It uses ADSI so there is no need for the Active Directory module installation.

You can change the first two lines to suit your needs in finding some other resources and the service name to check the status as well.


$SPNKeyword = 'VeeamAgentWindows'
$ServiceKeyword = 'Veeam'

Try {
$adsiSearcher = [adsisearcher]"(&(objectCategory=computer)(servicePrincipalName=*$($SPNKeyword)*))"
$propList = 'CanonicalName', 'description', 'name', 'operatingSystem', 'ServicePrincipalName'
ForEach ($prop in $propList) { [void]$adsiSearcher.PropertiesToLoad.Add($prop) }
$adsiSearcher.FindAll() | ForEach-Object {
Write-Host "Processing $($_.Properties['name'][0]) " -ForegroundColor Yellow
[PSCustomObject]([ordered]@{
Name = $_.Properties['name'][0]
Description = $_.Properties['description'][0]
OperatingSystem = $_.Properties['operatingSystem'][0]
IPAddresses = $(Try { [System.Net.Dns]::GetHostEntry($_.Properties['name'][0]).AddressList.Where({ $_.AddressFamily -eq 'InterNetwork' }).IPAddressToString -join ', ' } Catch { "<$($_.Exception.Message)>" })
UptimeStatus = If (Test-Connection -ComputerName $_.Properties['name'][0] -Count 2 -Quiet -ErrorAction SilentlyContinue) { 'Online' } else { 'Offline' }
ServiceStatus = $(Try { (Get-Service -Name "*$($ServiceKeyword)*" -ComputerName $_.Properties['name'][0] -Verbose -ErrorAction Continue | ForEach-Object { "[$($_.Name): $($_.Status)]" }) -join '; ' } Catch { "<$($_.Exception.Message)>" })
ServicePrincipalName = $_.Properties['servicePrincipalName'] -join ', '
OULocation = Split-Path -Path $_.Properties['CanonicalName'][0] -Parent
})
} | Sort-Object Name | Out-GridView -Title "Total $($adsiSearcher.FindAll().Count) object(s) returned containing the SPN keyword '$($SPNKeyword)' and '$($ServiceKeyword)' Service"
}
Finally {
If ($adsiSearcher) { $adsiSearcher.Dispose() }
}

The output of the script above is the console Out-GridView for quick check and sorting.

 

However, if you require the output as .CSV file, you can replace the line:

	} | Sort-Object Name | Out-GridView -Title "Total $($adsiSearcher.FindAll().Count) object(s) returned containing the SPN keyword '$($SPNKeyword)' and '$($ServiceKeyword)' Service"

 

with the below line:

    } | Sort-Object Name | Export-CSV -Path C:\TheResult.CSV -NoTypeInformation

 

Feel free to modify and improve the script above.

Hope this helps you all in discovering some good information at a glance.


7 comments

Userlevel 7
Badge +20

Very cool script another to add to my collection. Thanks for sharing 👍

Userlevel 7
Badge +17

Nice share! Well done @vAdmin 

Userlevel 7
Badge +2

Thank you @coolsport00 ,This is read only script so it is safe to run in any environment.

Userlevel 7
Badge +2

Very cool script another to add to my collection. Thanks for sharing 👍

No worries @Chris.Childerhose :-)

Userlevel 7
Badge +17

Thank you @coolsport00 ,This is read only script so it is safe to run in any environment.

Very cool!

Userlevel 7
Badge +7

@vAdmin This is so cool! Nice job.

Userlevel 7
Badge +2

@vAdmin This is so cool! Nice job.

@CarySun thank you, hopefully this can be useful script.

Comment