I'm trying to use DacServices from a Powershell Core script. Unfortunately, it seems DacServices requires System.Diagnostics.Eventing.EventDescriptor, which isn't available in .NET 6. I'm using Powershell Core 7.2.5. Is there a convenient way around this?
I'm loading the types with this code:
$sqlServerDacPaths = "${env:ProgramFiles}\Microsoft SQL Server\150\DAC\bin\Microsoft.SqlServer.Dac.dll", "${env:ProgramFiles}\Microsoft SQL Server\150\DAC\bin\Microsoft.SqlServer.Dac.Extensions.dll"
foreach ($path in $sqlServerDacPaths) {
if (Test-Path $path) {
Write-Host "Adding $path"
Add-Type -Path $path
}
}
# Instantiate DacServices
$dacServices = New-Object Microsoft.SqlServer.Dac.DacServices $connectionString
The exception I get instantiating DacServices is:
The type initializer for 'Microsoft.SqlServer.Dac.DacServices' threw an exception... Could not load type 'System.Diagnostics.Eventing.EventDescriptor' from assembly 'System.Core, Version=4.0.0.0
I've tried both the SQL 15 and 16 versions of DacServices without luck.
Sorry for late anwser, you can try running the script in lower version of Powershell, Powershell 5.1 is built on top of the .NET Framework v4.5 which has access to type System.Diagnostics.Eventing.EventDescriptor
It worked in my case:
powershell -Version 5.1 pathToYourScript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With