Skip to content

Instantly share code, notes, and snippets.

@alx9r
Created May 5, 2020 14:23
Show Gist options
  • Save alx9r/a1c6d140db59e105d17325e46255689d to your computer and use it in GitHub Desktop.
Save alx9r/a1c6d140db59e105d17325e46255689d to your computer and use it in GitHub Desktop.
x-OdbcDsn workarounds (PowerShell/PowerShell#12427)
# Get
Invoke-CimMethod -ClassName MSFT_OdbcDsnTask `
-Namespace ROOT\Microsoft\Windows\Wdac `
-MethodName 'Get' `
-Arguments @{
Name = $Name
DsnType = [string]$DsnType
Platform = $Platform
DriverName = $DriverName
}
# Add DSN
Invoke-CimMethod -ClassName MSFT_OdbcDsnTask `
-Namespace ROOT\Microsoft\Windows\Wdac `
-MethodName 'Add' `
-Arguments @{
Name = $Name
DsnType = [string]$DsnType
Platform = $Platform
DriverName = $DriverName
}
# Remove DSN
Invoke-CimMethod -ClassName MSFT_OdbcDsnTask `
-Namespace ROOT\Microsoft\Windows\Wdac `
-MethodName 'RemoveByName' `
-Arguments @{
Name = $Name
DsnType = [string]$DsnType
Platform = $Platform
DriverName = $DriverName
}
# Set DSN Property
Invoke-CimMethod -ClassName MSFT_OdbcDsnTask `
-Namespace ROOT\Microsoft\Windows\Wdac `
-MethodName 'SetByName' `
-Arguments @{
Name = $Name
DsnType = [string]$DsnType
Platform = $Platform
DriverName = $DriverName
SetPropertyValue = ,"$Key=$Value"
}
# Remove DSN Property
Invoke-CimMethod -ClassName MSFT_OdbcDsnTask `
-Namespace ROOT\Microsoft\Windows\Wdac `
-MethodName 'SetByName' `
-Arguments @{
Name = $Name
DsnType = [string]$DsnType
Platform = $Platform
DriverName = $DriverName
RemovePropertyValue = ,$Key
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment