PowerShell DSC Cheat Sheet

If you installed DSC resources from the PowerShell Gallery, you can use the following command to see a list of all the DSC resources that are available on your system:

Get-DscResource

If you want to know the syntax of a resource and the options that are configurable with it, simply specify the DSC module name and the specific resource name:

Get-DscResource -Module psdesiredstateconfiguration -Name User -Syntax

The following resources were exported in exactly that way:

Archive Resource Example

The archive resource gives you a mechanism to unpack archive (.zip) files at a specific path.

Archive [String] #ResourceName
{
    Destination = [string]
    Path = [string]
    [Checksum = [string]{ CreatedDate | ModifiedDate | SHA-1 | SHA-256 | SHA-512 }]
    [Credential = [PSCredential]]
    [DependsOn = [string[]]]
    [Ensure = [string]{ Absent | Present }]
    [Force = [bool]]
    [PsDscRunAsCredential = [PSCredential]]
    [Validate = [bool]]
}

Script Resource Example

The script resource gives you a mechanism to run Windows PowerShell script blocks on target nodes. The TestScript block runs first. If it returns False, the SetScript block will run. The GetScript block will run when you invoke the Get-DscConfiguration cmdlet (more on that cmdlet on the flipside of this sheet). GetScript must return a hash table.

Script [String] #ResourceName
{
    GetScript = [string]
    SetScript = [string]
    TestScript = [string]
    [Credential = [PSCredential]]
    [DependsOn = [string[]]]
    [PsDscRunAsCredential = [PSCredential]]
}

Registry Resource Example

The registry resource gives you a mechanism to manage registry keys and values.

Registry [String] #ResourceName
{
    Key = [string]
    ValueName = [string]
    [DependsOn = [string[]]]
    [Ensure = [string]{ Absent | Present }]
    [Force = [bool]]
    [Hex = [bool]]
    [PsDscRunAsCredential = [PSCredential]]
    [ValueData = [string[]]]
    [ValueType = [string]{ Binary | Dword | ExpandString | MultiString | Qword | String }]
}

Package Resource Example

The package resource gives you a mechanism to install and manage packages, such as MSI and setup.exe packages, on a target node.

Package [String] #ResourceName
{
    Name = [string]
    Path = [string]
    ProductId = [string]
    [Arguments = [string]]
    [Credential = [PSCredential]]
    [DependsOn = [string[]]]
    [Ensure = [string]{ Absent | Present }]
    [LogPath = [string]]
    [PsDscRunAsCredential = [PSCredential]]
    [ReturnCode = [UInt32[]]]
}

Environment Resource Example

The environment resource gives you a mechanism to manage system environment variables.

Environment [String] #ResourceName
{
    Name = [string]
    [DependsOn = [string[]]]
    [Ensure = [string]{ Absent | Present }]
    [Path = [bool]]
    [PsDscRunAsCredential = [PSCredential]]
    [Value = [string]]
}

Group Resource Example

The group resource gives you a mechanism to manage local groups on the target node.

Group [String] #ResourceName
{
    GroupName = [string]
    [Credential = [PSCredential]]
    [DependsOn = [string[]]]
    [Description = [string]]
    [Ensure = [string]{ Absent | Present }]
    [Members = [string[]]]
    [MembersToExclude = [string[]]]
    [MembersToInclude = [string[]]]
    [PsDscRunAsCredential = [PSCredential]]
}

User Resource Example

The user resource gives you a mechanism to manage local user accounts on the target node.

User [String] #ResourceName
{
    UserName = [string]
    [DependsOn = [string[]]]
    [Description = [string]]
    [Disabled = [bool]]
    [Ensure = [string]{ Absent | Present }]
    [FullName = [string]]
    [Password = [PSCredential]]
    [PasswordChangeNotAllowed = [bool]]
    [PasswordChangeRequired = [bool]]
    [PasswordNeverExpires = [bool]]
    [PsDscRunAsCredential = [PSCredential]]
}

Service Resource Example

The service resource gives you a mechanism to manage services on the target node.

Service [String] #ResourceName
{
    Name = [string]
    [BuiltInAccount = [string]{ LocalService | LocalSystem | NetworkService }]
    [Credential = [PSCredential]]
    [Dependencies = [string[]]]
    [DependsOn = [string[]]]
    [Description = [string]]
    [DisplayName = [string]]
    [Ensure = [string]{ Absent | Present }]
    [Path = [string]]
    [PsDscRunAsCredential = [PSCredential]]
    [StartupType = [string]{ Automatic | Disabled | Manual }]
    [State = [string]{ Running | Stopped }]
}