-
-
Save vedmichv/5c09ef81c2854236dc4e to your computer and use it in GitHub Desktop.
This file contains 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
$DefaultPassword = "Password2015" | |
$SecurePassword = $DefaultPassword | ConvertTo-SecureString -AsPlainText -Force | |
$UserName = "contoso\admin" | |
$SetupCredential = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword | |
$SAPass = $DefaultPassword | ConvertTo-SecureString -AsPlainText -Force | |
$SAUserName = "sa" | |
$saCreds = New-Object System.Management.Automation.PSCredential -ArgumentList $SAUserName, $SAPass | |
$configdata = @{ | |
AllNodes = @( | |
@{ | |
NodeName = 'S2' | |
PSDscAllowPlainTextPassword = $true | |
RebootNodeIfNeeded = $true | |
Role = 'web-app-db' | |
Features = @("Web-WebServer","Web-App-Dev","Web-Net-Ext45","Web-Asp-Net45","Web-ISAPI-Ext","Web-ISAPI-Filter","Web-Mgmt-Tools", "Web-Scripting-Tools") | |
SourceSitePath = "\\s1\ShareFolder\mysite\" | |
DestinationPathSitePath = "C:\itweek2015\mysite\" | |
ServiceName = "myservice" | |
ServiceBinPath = "C:\itweek2015\myservice\" | |
SourcePath = "\\s1\ShareFolder\myservice\" | |
ExecutionFile = "C:\itweek2015\myservice\NorthWind.console.exe" | |
SQLFeatures ="SQLENGINE,SSMS" | |
SQLUpdateSource = "c:\temp" | |
SetupCredential =$SetupCredential | |
saCreds = $saCreds | |
SQLDatabaseSource = "\\s1\ShareFolder\SQL\instnwnd.sql" | |
WindowsPowerShellExtensions = "\\s1\ShareFolder\SQL\PowerShellTools.msi" | |
SharedManagementObjects = "\\s1\ShareFolder\SQL\SharedManagementObjects.msi" | |
}, | |
@{ | |
NodeName = "S1" | |
Role = "SQLServer" | |
}, | |
@{ | |
NodeName = "S3" | |
Role = "Service" | |
} | |
); | |
NonNodeData = "" | |
} | |
Configuration RogaApplication | |
{ | |
Import-DscResource -Module xSQLServer | |
Import-DSCResource -ModuleName xPendingReboot | |
#Import-DscResource -Module xCredSSP | |
Import-DscResource -Module xWebAdministration | |
#Import-DscResource -Module PSDesiredStateConfiguration -Name NTFSPermission | |
Node $AllNodes.Where{$_.Role -eq "web-app-db"}.NodeName { | |
#Install IIS | |
foreach ($Feature in $Node.Features) { | |
WindowsFeature $Feature | |
{ | |
Ensure = "Present" | |
Name = $Feature | |
} | |
} | |
# Configure site | |
File DeploySite { | |
Ensure = "Present" # You can also set Ensure to "Absent" | |
Type = "Directory" # Default is "File". | |
Recurse = $true # Ensure presence of subdirectories, too | |
SourcePath = $Node.SourceSitePath | |
DestinationPath = $Node.DestinationPathSitePath | |
} | |
xWebAppPool mypool { | |
Ensure = "Present" | |
Name = "mypool" | |
State = "Started" | |
DependsOn = "[xWebsite]DefaultWebSite" | |
} | |
xWebsite DefaultWebSite { | |
Ensure = "Absent" | |
Name = "Default Web Site" | |
PhysicalPath = "C:\inetpub\wwwroot" | |
DependsOn = "[File]DeploySite" | |
} | |
xWebsite MySite { | |
Ensure = "Present" | |
Name = "MySite" | |
PhysicalPath = "c:\itweek2015\mysite" | |
State = "Started" | |
ApplicationPool = "DefaultAppPool" | |
DependsOn = "[xWebAppPool]mypool" | |
} | |
<# | |
NTFSPermission AppDataSecurity { | |
Ensure = "Present" | |
Account = "IIS AppPool\DefaultAppPool" | |
Access = "Allow" | |
Path = "c:\itweek2015\mysite" | |
Rights = "FullControl" | |
NoInherit =$true | |
} | |
#> | |
#Install myservice and config | |
Script InstallService { | |
GetScript = Format-DscScriptBlock -Node $Node -ScriptBlock { | |
return @{ | |
Result = if((get-service -name *$Node.ServiceName*)) {echo "Service deployed" } else {echo "Service NOT deployed"} | |
} | |
} | |
SetScript = Format-DscScriptBlock -Node $Node -ScriptBlock { | |
write-verbose "running InstallService"; | |
write-verbose "ServiceName = $Node.ServiceName"; | |
write-verbose "ExecutionFile = $Node.ExecutionFile"; | |
C:\\Windows\\system32\\cmd.exe /c sc create $Node.ServiceName binPath= $Node.ExecutionFile | |
} | |
TestScript = Format-DscScriptBlock -Node $Node -ScriptBlock { | |
write-verbose "running InstallService"; | |
write-verbose "ServiceName = $Node.ServiceName, Source = $Node.ServiceBinPath Destination=$Node.ServiceBinPath"; | |
write-verbose "ExecutionFile = $Node.ExecutionFile"; | |
if((get-service -name *$Node.ServiceName*)) | |
{return $true} | |
else | |
{return $false} | |
} | |
DependsOn = "[File]DeployService" | |
} | |
File DeployService { | |
Ensure = "Present" # You can also set Ensure to "Absent" | |
Type = "Directory" # Default is "File". | |
Recurse = $true # Ensure presence of subdirectories, too | |
SourcePath = $Node.SourcePath | |
DestinationPath = $Node.ServiceBinPath | |
} | |
Service ConfigService { | |
Name = $Node.ServiceName | |
StartupType = "Automatic" | |
State = "Running" | |
DependsOn = "[Script]InstallService" | |
} | |
Log ParamLog { | |
Message = "$(Format-DscScriptBlock -Node $Node -ScriptBlock { running InstallService $Node.SQLAdminCredentionalUser | |
SQLAdminCredentionalPassword= $Node.SQLAdminCredentionalPassword}) ` | |
Running SQLInstall. PackagePath = $Node.SQLAdminCredentionalUser `n SQLAdminCredentionalPassword= $Node.SQLAdminCredentionalPassword" | |
} | |
# Isntall SQL and fill | |
xSQLServerSetup InstallSQL { | |
InstanceName = "MSSQL" | |
SetupCredential = $Node.SetupCredential | |
SourcePath = "C:\temp" | |
SourceFolder = "\SQL" | |
Features= $Node.SQLFeatures | |
SecurityMode = 'SQL' | |
SAPwd = $Node.saCreds | |
UpdateEnabled = $true | |
UpdateSource = $Node.SQLUpdateSource | |
} | |
File SharedManagementObjects { | |
Ensure = "Present" # You can also set Ensure to "Absent" | |
SourcePath = $Node.SharedManagementObjects | |
DestinationPath = 'C:\temp\SharedManagementObjects.msi' | |
} | |
Package SharedManagementObjects { | |
Ensure = "Present" # You can also set Ensure to "Absent" | |
Path = "c:\v_DSC\ShareFolder\SQL\SharedManagementObjects.msi" | |
Name = "Microsoft SQL Server 2014 Management Objects (x64)" | |
ProductId = '1F9EB3B6-AED7-4AA7-B8F1-8E314B74B2A5' | |
DependsOn = "[File]SharedManagementObjects" | |
} | |
File WindowsPowerShellExtensions { | |
Ensure = "Present" # You can also set Ensure to "Absent" | |
SourcePath = $Node.WindowsPowerShellExtensions | |
DestinationPath = "C:\temp\PowersShellTools.msi" | |
#DependsOn = "[xSQLServerSetup]InstallSQL" | |
} | |
Package WindowsPowerShellExtensions { | |
Ensure = "Present" # You can also set Ensure to "Absent" | |
Path = "c:\temp\PowersShellTools.msi" | |
Name = "Windows PowerShell Extensions for SQL Server 2014 " | |
ProductId = '6A7D0067-CF88-453E-9EA5-A2008EC7CB19' | |
DependsOn = "[File]WindowsPowerShellExtensions" | |
} | |
File SQLDatabaseSource { | |
Ensure = "Present" # You can also set Ensure to "Absent" | |
SourcePath = $Node.SQLDatabaseSource | |
DestinationPath = 'C:\temp\instnwnd.sql' | |
} | |
Script FillDatabase { | |
GetScript = Format-DscScriptBlock -Node $Node -ScriptBlock { | |
return @{result="true" } | |
} | |
SetScript = Format-DscScriptBlock -Node $Node -ScriptBlock { | |
write-verbose "Fill database"; | |
invoke-sqlcmd -InputFile "c:\temp\instnwnd.sql" -ServerInstance "s1\MSSQL" -ErrorAction Stop -username "sa" -password "Password2015" | |
} | |
TestScript = Format-DscScriptBlock -Node $Node -ScriptBlock { | |
write-verbose "Check fill database"; | |
try { | |
$ResultOfFillDatabase = invoke-sqlcmd -Query 'use Northwind;select top 1 * from orders' -ServerInstance "s1\MSSQL" -ErrorAction Stop -username "sa" -password "Password2015" | |
return $true | |
} | |
catch {return $false} | |
} | |
DependsOn = "[Package]WindowsPowerShellExtensions" | |
} | |
} | |
} | |
function Format-DscScriptBlock() | |
{ | |
param( | |
[parameter(Mandatory=$true)] | |
[System.Collections.Hashtable] $node, | |
[parameter(Mandatory=$true)] | |
[System.Management.Automation.ScriptBlock] $scriptBlock | |
) | |
$result = $scriptBlock.ToString(); | |
foreach( $key in $node.Keys ) | |
{ | |
$result = $result.Replace("`$Node.$key", $node[$key]); | |
$result = $result.Replace("`$node.$key", $node[$key]); | |
} | |
return $result; | |
} | |
RogaApplication -ConfigurationData $configdata -OutputPath c:\v_DSC\TestPullServer\config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment