PowerShell Desired State Configuration - WindowsFeature Resource Demo
Scenario
Installing Windows Feature DSC. Are we installing? Nope, we are configuring the server as Web Server.
Demo
Let's see the demo. What Features we have in Windows Server 2012 R2 Data Center before we begin the demo we need to confirm if IIS is configured in the server. In this case no. Okay! Clear let's confirm it using PowerShell.
Get-WindowsFeature |
DSC Code
In the screenshot we have missed to add IncludeAllSubFeature to set true.
Configuration WebServer { Node $env:ComputerName { WindowsFeature WebServer { Name = 'Web-Server' Ensure = 'Present' IncludeAllSubFeature = $true } } } WebServer Start-DscConfiguration -Path C:\WebServer -Wait -Verbose -Force |
Total Time Consumed to Configure Web Server
001 002 |
$TimeSpan = [TimeSpan]::FromSeconds(577.239) "{0:hh:mm:ss}" -f ([datetime]$TimeSpan.Ticks) |
Progress
The above picture confirms that web server and IIS tools were not installed. As we said earlier let's configure it :)
Note: Not included all features but in code we have included it.
Now we have included the All Required Features. So the time consumption is 12 minutes approximately.
Final Output
MOF File
/* @TargetNode='DSC' @GeneratedBy=ChenV @GenerationDate=12/22/2014 12:42:44 @GenerationHost=DSC */ instance of MSFT_RoleResource as $MSFT_RoleResource1ref { ResourceID = "[WindowsFeature]WebServer"; IncludeAllSubFeature = True; Ensure = "Present"; SourceInfo = "::5::9::WindowsFeature"; Name = "Web-Server"; ModuleName = "PSDesiredStateConfiguration"; ModuleVersion = "1.0"; ConfigurationName = "WebServer"; }; instance of OMI_ConfigurationDocument { Version="2.0.0"; MinimumCompatibleVersion = "1.0.0"; CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"}; Author="ChenV"; GenerationDate="12/22/2014 12:42:44"; GenerationHost="DSC"; Name="WebServer"; }; |