03 September,2019 by Rambler
Powershell comes with the SQL Server Drivers packed , so you can connect to SQL Server without setting up an ODBC DSN. This makes it easy to connect to remote SQL Servers. What if you needed to connect to other database server platforms through Powershell ? A typical method used is to set up a DSN through ODBC - utilising the drivers installed for the remote database server. As part of setting up DSNs , you may need to access remote servers and identify the current DSNs. Powershell offers a method to get the DSN list from the remote server.
As a starting point these are some Powershell cmdlets to gather some ODBC DSN details
--To list the ODBC drivers on a local Windows server
Get-OdbcDriver
--Gets the ODBC data source names from the local server
Get-ODBCDSN
--Limit the list to 32-bit platform or 64 -bit platform
Get-ODBCDSN -Platform 32-bit
Get-OdbcDSN -Platform "64-bit"
--list all obcs , but show only name
Get-OdbcDSN | select name
--list all odbc - on a remote server
Get-OdbcDSN -Cimsession "my_remote_server_name"
So far these examples are to access local details. What if you needed to access a remote server? - it could be for various reasons, such as reporting or as part of an installation script.
To access the remote server you can utilise the -Cimsession switch . The -Cimsession switch
A Common Information Model (CIM) session is a client-side object representing a connection to a local or remote. CimSessions are alternatives to Powershell sessions , both methods have pros and cons
Gets the ODBC data source names from a remote server
Get-ODBCDSN -Cimsession my_remote_server
What methods do you use to gather DSN details from remote servers?
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |