Product: PowerShell Universal
Version: 5.4.1
Anyone know of a way to get a list of the Event Hubs thats not reliant on an agent being connected. eg trying to work out how I can have a list of hubs and include any where one of them has no agents connected - for things like upgrades, new hubs, fault finding, etc
The only way I can think of is to dump the contents of eventhubs.ps1
into a variable and extract the names out of each line, to then do what you need from there.
Thought I’d be clever and read it from the Database, but the EventHubs table is empty. Teach me for trying to be clever
1 Like
Yeah. IDK why there’s not an cmdlet to just pull the names into an array. Maybe submit a feature request for that.
And, that is weird that the EventHubs table is empty (in mine too). I wonder why the table even exists if it’s not being used.
adam
March 18, 2025, 1:58pm
5
We need to a cmdlet for this…
Long story on schema:
The same schema is used for the both the internal configuration data (in-memory SQLite) as well as the persistent database. The goal is to eventually avoid having the in-memory database in multi-node systems. This results in a single database containing all the configuration. Changes on one node would update other nodes without git sync. It gets murky with files like modules\scripts so git sync might still be needed.
This isn’t something we are actively working on but rather wanted to set up the system in a way where it would eventually be possible.
2 Likes
Yeah, no sweat at all, its not a big thing, just making some detais more visible for less technical people at my work.
if anyone is interested heres the script I pulled together to get and report on the list of hubs and their connections
Get-PSUEventHubData.ps1
# Get the eventhub config
$eventHubsContent = Get-Content -Path "$($Repository)\.universal\eventHubs.ps1" -Raw
# Find all the command calls in the scrit
$ast = [System.Management.Automation.Language.Parser]::ParseInput($eventHubsContent, [ref]$null, [ref]$null)
$astFindFunctionsDelegate = { param($ast) $ast -is [System.Management.Automation.Language.CommandAst] }
$astFindFunctions = $ast.FindAll($astFindFunctionsDelegate, $true)
# Parse the New-PSUEventHub calls to get the Nme of the hub
$EventHubNames = @()
foreach ($astFunction in $astFindFunctions)
{
if($astFunction.CommandElements[0].Value -eq "New-PSUEventHub")
{
for ($i = 0; $i -lt $astFunction.CommandElements.Count; $i++) {
if($astFunction.CommandElements[$i].ParameterName -eq "Name")
{
if($i -lt $astFunction.CommandElements.Count - 2)
{
$EventHubNames += $astFunction.CommandElements[$i+1].Value
break
}
}
}
}
}
#Now get and parse the connections - both active and all
Write-Information "Grabbing all EventHub Connections..."
$connectionData = @()
$connections = @(Get-PSUEventHubConnection)
$activeConnections = @(Get-PSUEventHubConnection -Active)
#Build a table of the data we want to display
foreach ($EventHubName in $EventHubNames)
{
Write-Information "Getting the latest Connection for $($EventHubName)"
$myConnections = $activeConnections.Where({$_.EventHub -eq $EventHubName})
if($myConnections.Count -gt 0)
{
foreach ($active in $activeConnections)
{
$connectionData += [PSCustomObject]@{
Hub = $active.EventHub
Connected = $active.Connected
Disconnected = $active.Connected
Agent = $active.RemoteComputer
ConnectionId = $active.ConnectionId
Username = $active.RemoteUserName
State = "Active"
}
}
}
else {
$latestConnection = $myConnections.Where({$_.EventHub -eq $EventHubName}) | Sort-Object -Property Disconnected -Descending
if($latestConnection.Count -lt 1)
{
Write-Information "No previous connections found for $($EventHubName)"
$connectionData += [PSCustomObject]@{
Hub = $EventHubName
Connected = ""
Disconnected = ""
Agent = ""
ConnectionId = ""
Username = ""
State = "None"
}
}
else
{
Write-Information "Previous Connection found for $($EventHubName)"
$connections += [PSCustomObject]@{
Hub = $latestConnection[0].EventHub
Connected = $latestConnection[0].Connected
Disconnected = $latestConnection[0].Connected
Agent = $latestConnection[0].RemoteComputer
ConnectionId = $latestConnection[0].ConnectionId
Username = $latestConnection[0].RemoteUserName
State = "Active"
}
}
}
}
# return it so that we can call this and consume in an app
$connectionData
Ill mark this as a solution for now, so others can see it too
1 Like
For the record, I submitted a feature request for a new cmdlet to do this, and @adam already marked it as completed.
Thanks Jesse, saw that but figured Id share an interim too. Thanks for the help