Created
December 6, 2016 19:29
-
-
Save bobalob/b0d0584bde1d348a6a6e676c2e6222c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Configuration OdbcConfig | |
{ | |
Param( | |
[Parameter(Mandatory=$true)][ValidateNotNullorEmpty()]$SQLServerName, | |
[Parameter(Mandatory=$true)][ValidateNotNullorEmpty()]$DatabaseName, | |
[Parameter(Mandatory=$true)][ValidateNotNullorEmpty()]$ODBCName, | |
[Parameter(Mandatory=$true)][ValidateNotNullorEmpty()]$ComputerName | |
) | |
Import-DscResource -ModuleName 'PSDesiredStateConfiguration' | |
Node $ComputerName | |
{ | |
Script OdbcScript #Creates ODBC Connection | |
{ | |
SetScript = { | |
Write-verbose "Create ODBC Connection for $($Using:SQLServerName)" | |
$NewDsn = Add-OdbcDsn -Name "$($Using:ODBCName)" -DriverName "SQL Server" ` | |
-DsnType "System" -SetPropertyValue @( | |
"Server=$($Using:SQLServerName)", | |
"Database=$($Using:DatabaseName)", | |
"Description=$($Using:DatabaseName)" | |
) -PassThru | |
if ($NewDsn) { | |
Write-verbose "ODBC connection $($Using:ODBCName) created" | |
} else { | |
Write-verbose "Failed to create ODBC connection $($Using:ODBCName)" | |
} | |
} | |
TestScript = { | |
if (Get-OdbcDsn | ? {$_.Name -eq "$($Using:ODBCName)"}) { | |
Write-verbose "$($Using:ODBCName) - ODBC connection exists" | |
$true | |
} else { | |
Write-verbose "$($Using:ODBCName) - ODBC does not exist" | |
$false | |
} | |
} | |
GetScript = { | |
@{ Result = ((Get-OdbcDsn | ? {$_.Name -eq "$($Using:ODBCName)"}).Attribute.Server) } | |
} | |
} | |
} | |
} | |
OdbcConfig -OutputPath C:\DSC\ODBC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment