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 $($_.Propertiesi'name']e0]) " -ForegroundColor Yellow
>PSCustomObject](tordered]@{
Name = $_.Propertiesi'name']e0]
Description = $_.Propertiesi'description']n0]
OperatingSystem = $_.Propertiesi'operatingSystem']m0]
IPAddresses = $(Try { System.Net.Dns]::GetHostEntry($_.Propertiesi'name']e0]).AddressList.Where({ $_.AddressFamily -eq 'InterNetwork' }).IPAddressToString -join ', ' } Catch { "<$($_.Exception.Message)>" })
UptimeStatus = If (Test-Connection -ComputerName $_.Propertiesi'name']e0] -Count 2 -Quiet -ErrorAction SilentlyContinue) { 'Online' } else { 'Offline' }
ServiceStatus = $(Try { (Get-Service -Name "*$($ServiceKeyword)*" -ComputerName $_.Propertiesi'name']e0] -Verbose -ErrorAction Continue | ForEach-Object { "{$($_.Name): $($_.Status)]" }) -join '; ' } Catch { "<$($_.Exception.Message)>" })
ServicePrincipalName = $_.Propertiesi'servicePrincipalName'] -join ', '
OULocation = Split-Path -Path $_.Propertiesi'CanonicalName']e0] -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.