Product: PowerShell Universal
Version: 2026
I've been developing this App to retrieve polybase informatin from my SQL 2025 database. No matter what I do I can't get it to show any data. What do I need to do to fix it?
New-UDApp -Title "SQL 2025 PolyBase Manager" -Content {
Import-Module SqlServer -ErrorAction SilentlyContinue
New-UDTabs -Tabs {
New-UDTab -Text "External Sources" -Content {
New-UDTable -Id 'dsTable' -LoadData {
# 1. Force module loading in the background thread
Import-Module SqlServer -ErrorAction SilentlyContinue
try {
# 2. Use $using: to pull the global connection string
$Conn = $using:PolyBaseConnectionString
# 3. Fetch data
$Query = "SELECT name, location FROM sys.external_data_sources"
$Data = Invoke-Sqlcmd -ConnectionString $Conn -Query $Query -ErrorAction Stop
# 4. Construct a clean array (Never $null)
$FinalRows = if ($null -eq $Data) { @() } else { @($Data) }
# 5. EXPLICIT BINDER: Do not use the pipeline (|)
# This satisfies the 'Properties' mandatory check manually
Out-UDTableData -Data $FinalRows -Page $EventData.Page -TotalCount $FinalRows.Count
}
catch {
# Safety fallback to prevent the red toast
Out-UDTableData -Data @() -Page 0 -TotalCount 0
}
} -Columns @(
New-UDTableColumn -Property "name" -Title "Source"
New-UDTableColumn -Property "location" -Title "Path"
)
}
New-UDTab -Text "External Credentials" -Content {
New-UDButton -Text "Create New Credential" -OnClick {
# Documentation: Must use -Header, not -Title
Show-UDModal -Header "New Database Scoped Credential" -Content {
New-UDForm -Content {
New-UDTextbox -Id "cName" -Label "Name"
New-UDTextbox -Id "cId" -Label "Identity"
New-UDTextbox -Id "cSec" -Label "Secret" -Type "password"
} -OnSubmit {
try {
$Sql = "CREATE DATABASE SCOPED CREDENTIAL [$($EventData.cName)] WITH IDENTITY = N'$($EventData.cId)', SECRET = N'$($EventData.cSec)';"
Invoke-Sqlcmd -ConnectionString $PolyBaseConnectionString -Query $Sql -ErrorAction Stop
Show-UDToast -Message "Success" -Severity success
Sync-UDTable -Id 'credTable'
Hide-UDModal
} catch {
Show-UDToast -Message "Error: $($_.Exception.Message)" -Severity error
}
}
}
}
New-UDTable -Id 'credTable' -LoadData {
Import-Module SqlServer -ErrorAction SilentlyContinue
try {
$Conn = $using:PolyBaseConnectionString
$Data = Invoke-Sqlcmd -ConnectionString $Conn -Query "SELECT name, credential_identity as identity FROM sys.database_scoped_credentials" -ErrorAction Stop
$FinalRows = if ($null -eq $Data) { @() } else { @($Data) }
Out-UDTableData -Data $FinalRows -Page $EventData.Page -TotalCount $FinalRows.Count
} catch {
Out-UDTableData -Data @() -Page 0 -TotalCount 0
}
} -Columns @(
New-UDTableColumn -Property "name" -Title "Name"
New-UDTableColumn -Property "identity" -Title "Identity"
)
}
}
}-ErrorAction SilentlyContinueHey there,
First up, why are you using ‘-ErrorAction SilentlyContinue’?
If your SqlServer module fails to import or there’s an unexpected error you wont know about it.
There’s also no need to keep importing the module in multiple areas of the script, just stick the module in your modules folder and as long as it’s available it’ll auto load.
Where’s your global connection string defined? have you tried spitting out $Conn in your dashboard to see if it’s actually populated?
Take this all out of PSU and run it in a local PS session, does the SQL calls work standalone and return the data you need?
After removing error action silentlycontinue Have you checked logs and do you get any errors?
Personally I don’t use SqlServer, I just use Invoke-SqlCmd2 which is a dependency free version, you can find it on the psgallery i think but it’s easy to find on google.
I have my dashboard running in the context of a service account that has the required permissions to my db.
In my dashboard.ps1 I do:
$SQLConfig = @{
Server = $SQLServer
Database = $SQLDatabase
}
Which are defined as PSU variables, but equally you could just specify them in the pages too.
Then in my dashboard pages all I need to do is:
Invoke-SQLCmd2 @SQLConfig -query "....
It turns out that it is a scope issue. I define the connection string at the top of my file but every time I define a new tab I have to also define the connection string all over again.
if you use dynamic tabs you probably wont have that issue. You could also use a variable.