Hey I'm trying to use the dsc module and create a dsc_script to run something for me. I didn't find any documentation about it besides the dsc modeule itself. It would be helpful instead of using the exec command and put a powershell code. (If the module has this capability, why not?)
The code I have was adapted form [http://www.colinsalmcorner.com/post/install-and-configure-sql-server-using-powershell-dsc](http://www.colinsalmcorner.com/post/install-and-configure-sql-server-using-powershell-dsc)
I know that a puppet module for installing MSSQL already exist. I'm just trying to use the dsc_script resource.
dsc_script { 'InstallSQLServer':
dsc_getscript => '$sqlInstances = gwmi win32_service -computerName localhost | ? { $_.Name -match "mssql*" -and $_.PathName -match "sqlservr.exe" } | % { $_.Caption }
$res = $sqlInstances -ne $null -and $sqlInstances -gt 0
$vals = @{Installed = $res; InstanceCount = $sqlInstances.count}
$vals',
dsc_setscript => '$setupDriveLetter = (Mount-DiskImage -ImagePath \\servershare\Microsoft\SQL2014\en_sql_server_2014_enterprise_edition_x64_dvd_3932700.iso -PassThru | Get-Volume).DriveLetter + ":"
if ($setupDriveLetter -eq $null) {
throw "Could not mount SQL install iso"
}
Write-Verbose "Drive letter for iso is: $setupDriveLetter"
# run the installer using the ini file
$cmd = "$setupDriveLetter\Setup.exe /ConfigurationFile=\\servershare\database\ConfigurationFile.ini /SQLSVCPASSWORD=P2ssw0rd /AGTSVCPASSWORD=P2ssw0rd /SAPWD=P2ssw0rd"
Write-Verbose "Running SQL Install - check %programfiles%\Microsoft SQL Server\120\Setup Bootstrap\Log\ for logs..."
Invoke-Expression $cmd | Write-Verbose',
dsc_testscript => '$sqlInstances = gwmi win32_service -computerName localhost | ? { $_.Name -match "mssql*" -and $_.PathName -match "sqlservr.exe" } | % { $_.Caption }
$res = $sqlInstances -ne $null -and $sqlInstances -gt 0
if ($res) {
Write-Verbose "SQL Server is already installed"
} else {
Write-Verbose "SQL Server is not installed"
}
$res'
}
↧