Share via


PowerShell 5.0 Desired State Configuration Service Resource Demo

Install PowerShell 5.0 November Preview

Refer to this post for installing PowerShell 5.0 November Preview
http://social.technet.microsoft.com/wiki/contents/articles/29073.installing-powershell-5-0-november-preview.aspx

Exploring Resources

Get-DscResource

So now we can see all available resources. Note: For now let's explore the Out of the box Resources.In this demo let's see how the resource Service can be used. To know the Syntax we can use the below code.

Get-DscResource -Name Service -Syntax

Output

Set BITS service

In this demo let's see how to configure a BITS service. Deafault BITS service was set to STOP and start type is manual. So we will change it to Running and Start up type as Automatic. Code

Configuration SetBITS
{
    Node $env:ComputerName
    {
        Service SetBITS
        {
            Name = "BITS"
            State = "Running"
            StartupType = "Automatic"
        }
    }
}

SetBITS

Start-DscConfiguration -Path C:\SetBITS -Wait -Verbose -Force

Screen Shots

We have applied the configuration successfully. Let's see the MOF file code

/*
@TargetNode='DSC'
@GeneratedBy=ChenV
@GenerationDate=12/22/2014 11:25:00
@GenerationHost=DSC
*/

instance of MSFT_ServiceResource as $MSFT_ServiceResource1ref
{
ResourceID = "[Service]SetBITS";
 State = "Running";
 SourceInfo = "::5::9::Service";
 Name = "BITS";
 StartupType = "Automatic";
 ModuleName = "PSDesiredStateConfiguration";
 ModuleVersion = "1.0";

 ConfigurationName = "SetBITS";

};
instance of OMI_ConfigurationDocument
{
 Version="2.0.0";
 MinimumCompatibleVersion = "1.0.0";
 CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};
 Author="ChenV";
 GenerationDate="12/22/2014 11:25:00";
 GenerationHost="DSC";
 Name="SetBITS";
};

Result