### Install and Import PSDscResources Source: https://context7.com/powershell/psdscresources/llms.txt Installs the PSDscResources module from the PowerShell Gallery and imports it for use in DSC configurations. Also shows how to apply a DSC configuration. ```powershell # Install the module from PowerShell Gallery Install-Module PSDscResources # Import in your DSC configuration Import-DscResource -ModuleName PSDscResources # Apply a configuration Start-DscConfiguration -Path .\MyConfiguration -Wait -Verbose ``` -------------------------------- ### Install PSDscResources Module Source: https://github.com/powershell/psdscresources/blob/dev/README.md Install the PSDscResources module from the PowerShell Gallery to update your in-box resources. ```powershell Install-Module PSDscResources ``` -------------------------------- ### Install or Uninstall Windows Package Cab Files Source: https://context7.com/powershell/psdscresources/llms.txt Use the WindowsPackageCab resource to install or uninstall packages from Windows cabinet (.cab) files. This resource is compatible with Nano Server and requires the DISM PowerShell module. It allows specifying the source path and logging for the operation. ```powershell Configuration WindowsPackageCabExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Install a CAB package WindowsPackageCab InstallPackage { Name = 'MyLanguagePack' Ensure = 'Present' SourcePath = 'C:\Packages\lp-en-us.cab' LogPath = 'C:\Logs\LanguagePack_Install.log' } # Remove a CAB package WindowsPackageCab RemovePackage { Name = 'OldUpdatePackage' Ensure = 'Absent' SourcePath = 'C:\Packages\old-update.cab' } } } ``` -------------------------------- ### Install and Uninstall Windows Features Source: https://context7.com/powershell/psdscresources/llms.txt Use the WindowsFeature resource to install or uninstall specific Windows roles or features. Ensure the target node is Windows Server 2008 or later and has access to DISM and ServerManager modules. Logs can be directed to a specified path. ```powershell Configuration WindowsFeatureExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Install a Windows feature WindowsFeature InstallWebServer { Name = 'Web-Server' Ensure = 'Present' IncludeAllSubFeature = $true LogPath = 'C:\Logs\WebServer_Install.log' } # Install Telnet client WindowsFeature TelnetClient { Name = 'Telnet-Client' Ensure = 'Present' } # Uninstall a feature WindowsFeature RemoveFeature { Name = 'Windows-Defender' Ensure = 'Absent' } } } ``` -------------------------------- ### WindowsProcess Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Manages the starting and stopping of Windows processes. ```APIDOC ## WindowsProcess ### Description Provides a mechanism to start and stop a Windows process. ### Parameters #### Request Body - **Path** (String) - Required - The executable file of the process. - **Arguments** (String) - Required - A single string containing all the arguments to pass to the process. - **Credential** (PSCredential) - Optional - The credential of the user account to run the process under. - **Ensure** (String) - Optional - Specifies whether or not the process should be running (Present or Absent). - **StandardOutputPath** (String) - Optional - The file path to which to write the standard output. - **StandardErrorPath** (String) - Optional - The file path to which to write the standard error output. - **StandardInputPath** (String) - Optional - The file path from which to receive standard input. - **WorkingDirectory** (String) - Optional - The file path to the working directory. ### Response #### Success Response (200) - **PagedMemorySize** (UInt64) - The amount of paged memory allocated for the process. - **NonPagedMemorySize** (UInt64) - The amount of nonpaged memory allocated for the process. - **VirtualMemorySize** (UInt64) - The amount of virtual memory allocated for the process. - **HandleCount** (SInt32) - The number of handles opened by the process. - **ProcessId** (SInt32) - The unique identifier of the process. - **ProcessCount** (SInt32) - The number of instances of the given process currently running. ``` -------------------------------- ### WindowsPackageCab Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Manages the installation or uninstallation of Windows cab files. ```APIDOC ## WindowsPackageCab ### Description Provides a mechanism to install or uninstall a Windows cab file. ### Parameters #### Request Body - **Name** (String) - Required - The name of the package to install or uninstall. - **Ensure** (String) - Required - Specifies whether the package should be installed (Present) or uninstalled (Absent). - **SourcePath** (String) - Required - The path to the cab file to install or uninstall the package from. - **LogPath** (String) - Optional - The path to a file to log the operation to. ``` -------------------------------- ### Archive Resource: Expand Archive Example Source: https://context7.com/powershell/psdscresources/llms.txt Demonstrates expanding a .zip archive to a specified destination. Includes options for validation with SHA-256 checksum and forcing an overwrite. Also shows how to remove expanded archive content. ```powershell Configuration ExpandArchiveExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Expand archive without validation Archive ExpandSimple { Path = 'C:\Archives\Application.zip' Destination = 'C:\Program Files\MyApplication' Ensure = 'Present' } # Expand archive with SHA-256 checksum validation and force overwrite Archive ExpandWithValidation { Path = 'C:\Archives\ConfigFiles.zip' Destination = 'C:\Config' Ensure = 'Present' Validate = $true Checksum = 'SHA-256' Force = $true } # Remove expanded archive content Archive RemoveArchive { Path = 'C:\Archives\OldApplication.zip' Destination = 'C:\Program Files\OldApplication' Ensure = 'Absent' } } } ``` -------------------------------- ### Set Members of a Group Source: https://github.com/powershell/psdscresources/blob/dev/README.md This example shows how to configure the members of a local group. The 'Members' property will replace all existing members with the ones specified. Ensure the group name is correctly provided. ```powershell Group { GroupName = "MyGroup" Members = @("DOMAIN\User1", "User2") Ensure = "Present" } ``` -------------------------------- ### Configure Windows Processes with WindowsProcess Source: https://context7.com/powershell/psdscresources/llms.txt Use the WindowsProcess resource to start or stop individual processes, including support for arguments, working directories, and output redirection. ```powershell Configuration WindowsProcessExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Start a process with arguments WindowsProcess StartGPResult { Path = 'C:\Windows\System32\gpresult.exe' Arguments = '/h C:\Reports\GroupPolicy.htm' Ensure = 'Present' } # Ensure a process is running with output capture WindowsProcess RunBackgroundTask { Path = 'C:\Tools\monitor.exe' Arguments = '--config C:\Config\monitor.json' Ensure = 'Present' StandardOutputPath = 'C:\Logs\monitor_stdout.log' StandardErrorPath = 'C:\Logs\monitor_stderr.log' WorkingDirectory = 'C:\Tools' } # Ensure a process is stopped WindowsProcess StopProcess { Path = 'C:\OldApp\legacy.exe' Arguments = '' Ensure = 'Absent' } } } ``` -------------------------------- ### MsiPackage Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Provides a mechanism to install and uninstall MSI packages on a target node. ```APIDOC ## MsiPackage Resource ### Description Installs or uninstalls MSI packages based on a provided product ID and file path. ### Parameters #### Key Parameters - **ProductId** (String) - Required - The identifying number (GUID) of the package. #### Required Parameters - **Path** (String) - Required - The path to the MSI file. #### Write Parameters - **Ensure** (String) - Optional - Specifies if the MSI should be installed (Present) or uninstalled (Absent). Default: Present. - **Arguments** (String) - Optional - Arguments passed to the MSI package. - **Credential** (PSCredential) - Optional - Credential to mount UNC paths. - **LogPath** (String) - Optional - Path to the log file. - **FileHash** (String) - Optional - Expected hash value of the MSI file. - **HashAlgorithm** (String) - Optional - Algorithm used for the hash. - **SignerSubject** (String) - Optional - Expected signer certificate subject. - **SignerThumbprint** (String) - Optional - Expected signer certificate thumbprint. - **ServerCertificateValidationCallback** (String) - Optional - PowerShell code for SSL validation. - **RunAsCredential** (PSCredential) - Optional - Credential to run the installation. ### Read-Only Properties - **Name** (String) - Display name of the package. - **InstallSource** (String) - Path to the MSI package. - **InstalledOn** (String) - Installation date. - **Size** (UInt32) - Size in MB. - **Version** (String) - Version number. - **PackageDescription** (String) - Description of the package. - **Publisher** (String) - Publisher of the package. ``` -------------------------------- ### Environment Resource: Manage Environment Variables Source: https://context7.com/powershell/psdscresources/llms.txt Provides a mechanism to configure and manage environment variables. Examples show creating a standard variable, adding a path variable, and removing a variable. ```powershell Configuration EnvironmentVariableExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Create a standard environment variable Environment CreateVariable { Name = 'MYAPP_CONFIG' Value = 'C:\Config\app.json' Ensure = 'Present' Path = $false Target = @('Process', 'Machine') } # Add to PATH environment variable Environment AddToPath { Name = 'Path' Value = 'C:\MyTools\bin' Ensure = 'Present' Path = $true Target = @('Machine') } # Remove an environment variable Environment RemoveVariable { Name = 'DEPRECATED_VAR' Ensure = 'Absent' } } } ``` -------------------------------- ### Manage MSI packages with MsiPackage Source: https://context7.com/powershell/psdscresources/llms.txt Installs or uninstalls MSI packages from local, UNC, or web paths with support for hash validation. ```powershell Configuration MsiPackageExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Install MSI from local file MsiPackage InstallApp { ProductId = '{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}' Path = 'C:\Installers\MyApplication.msi' Ensure = 'Present' Arguments = '/quiet /norestart' LogPath = 'C:\Logs\MyApp_Install.log' } # Install MSI from HTTP URL with hash validation MsiPackage InstallFromWeb { ProductId = '{B2C3D4E5-F678-9012-BCDE-F23456789012}' Path = 'https://download.example.com/tools/utility.msi' Ensure = 'Present' FileHash = '5D41402ABC4B2A76B9719D911017C592' HashAlgorithm = 'MD5' } # Uninstall MSI package MsiPackage UninstallOldApp { ProductId = '{C3D4E5F6-7890-1234-CDEF-345678901234}' Path = 'C:\Installers\OldApplication.msi' Ensure = 'Absent' } } } ``` -------------------------------- ### WindowsPackageCab Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Provides a mechanism to install or uninstall a package from a Windows cabinet (cab) file on a target node. ```APIDOC ## WindowsPackageCab ### Description Provides a mechanism to install or uninstall a package from a Windows cabinet (cab) file on a target node. This resource works on Nano Server. ### Requirements - Target machine must have access to the DISM PowerShell module. ``` -------------------------------- ### WindowsFeature Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Defines parameters for installing or uninstalling individual Windows roles or features. ```APIDOC ## WindowsFeature Resource ### Description Installs or uninstalls Windows roles or features. Not supported on Nano Server. ### Parameters #### Request Body - **Name** (String) - Required (Key) - Name of the role or feature. - **Credential** (PSCredential) - Optional - Credential to use for the operation. - **Ensure** (String) - Optional - Specifies if feature should be {Present | Absent}. - **IncludeAllSubFeature** (Boolean) - Optional - Whether to install all subfeatures (default: false). - **LogPath** (String) - Optional - Path to log file. ### Response #### Read-Only Properties - **DisplayName** (String) - The display name of the retrieved role or feature. ``` -------------------------------- ### Group Resource: Manage Local Groups Source: https://context7.com/powershell/psdscresources/llms.txt Manages local groups on a target node, including group membership. Examples demonstrate creating a group with specific members, adding members to an existing group, and removing members. ```powershell Configuration GroupManagementExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Create group and set exact membership Group DevelopersGroup { GroupName = 'Developers' Ensure = 'Present' Description = 'Development team members' Members = @('domain\user1', 'domain\user2', 'localuser') } # Add members to existing group without removing others Group AddToAdmins { GroupName = 'Administrators' Ensure = 'Present' MembersToInclude = @('domain\newadmin') } # Remove specific members from a group Group RemoveFromGroup { GroupName = 'RemoteDesktopUsers' Ensure = 'Present' MembersToExclude = @('domain\formeremployee') } } } ``` -------------------------------- ### Manage Windows Services with Service Resource Source: https://context7.com/powershell/psdscresources/llms.txt The Service resource configures and manages Windows services. It supports creating, starting, stopping, and configuring service properties like DisplayName, Description, and StartupType. ```powershell Configuration ServiceExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Create and start a new service Service CreateService { Name = 'MyAppService' Ensure = 'Present' Path = 'C:\Program Files\MyApp\service.exe' DisplayName = 'My Application Service' Description = 'Handles background tasks for MyApp' StartupType = 'Automatic' State = 'Running' } # Configure existing service to run under specific account Service ConfigureService { Name = 'CustomService' Ensure = 'Present' BuiltInAccount = 'LocalService' StartupType = 'Automatic' State = 'Running' StartupTimeout = 60000 } # Ensure service is stopped and disabled Service DisableService { Name = 'UnwantedService' Ensure = 'Present' StartupType = 'Disabled' State = 'Stopped' } # Remove a service Service RemoveService { Name = 'DeprecatedService' Ensure = 'Absent' } } } ``` -------------------------------- ### Manage Multiple Windows Features with WindowsFeatureSet Source: https://context7.com/powershell/psdscresources/llms.txt The WindowsFeatureSet resource allows for the configuration of multiple Windows features simultaneously with common settings. This is useful for installing sets of related features like web server components or remote administration tools. ```powershell Configuration WindowsFeatureSetExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Install multiple features with all subfeatures WindowsFeatureSet WebServerFeatures { Name = @('Web-Server', 'Web-Mgmt-Tools', 'Web-Asp-Net45') Ensure = 'Present' IncludeAllSubFeature = $true LogPath = 'C:\Logs\FeatureInstall.log' } # Install remote administration tools WindowsFeatureSet RSATTools { Name = @('RSAT-AD-Tools', 'RSAT-DNS-Server', 'RSAT-File-Services') Ensure = 'Present' } } } ``` -------------------------------- ### Configure a Complete Web Server Environment Source: https://context7.com/powershell/psdscresources/llms.txt Demonstrates a comprehensive DSC configuration for a web server, including IIS features, application deployment, environment variables, registry settings, and user/group management. ```powershell Configuration WebServerConfiguration { param ( [Parameter(Mandatory = $true)] [System.Management.Automation.PSCredential] $ServiceAccountCredential ) Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Install IIS and management tools WindowsFeatureSet WebFeatures { Name = @('Web-Server', 'Web-Mgmt-Console', 'Web-Asp-Net45') Ensure = 'Present' IncludeAllSubFeature = $true } # Create application directory Archive DeployApplication { Path = 'C:\Deploy\WebApp.zip' Destination = 'C:\inetpub\wwwroot\MyApp' Ensure = 'Present' Force = $true DependsOn = '[WindowsFeatureSet]WebFeatures' } # Set environment variables Environment AppSettings { Name = 'MYAPP_ENVIRONMENT' Value = 'Production' Ensure = 'Present' Target = @('Machine') } # Configure registry settings Registry AppRegistrySettings { Key = 'HKLM:\SOFTWARE\MyWebApp' ValueName = 'LogLevel' ValueType = 'String' ValueData = 'Warning' Ensure = 'Present' } # Create service account User ServiceAccount { UserName = 'WebAppService' Ensure = 'Present' Password = $ServiceAccountCredential PasswordNeverExpires = $true PasswordChangeNotAllowed = $true } # Add to IIS_IUSRS group Group IISUsers { GroupName = 'IIS_IUSRS' Ensure = 'Present' MembersToInclude = @('WebAppService') DependsOn = '[User]ServiceAccount' } # Ensure critical services are running ServiceSet RequiredServices { Name = @('W3SVC', 'WAS') Ensure = 'Present' State = 'Running' StartupType = 'Automatic' DependsOn = '[WindowsFeatureSet]WebFeatures' } } } ``` -------------------------------- ### Configure File Creation with Script Resource Source: https://context7.com/powershell/psdscresources/llms.txt Use the Script resource to run PowerShell script blocks for managing file content. Requires GetScript, TestScript, and SetScript functions. ```powershell Configuration ScriptResourceExample { param ( [Parameter(Mandatory = $true)] [String] $FilePath, [Parameter(Mandatory = $true)] [String] $FileContent ) Import-DscResource -ModuleName 'PSDscResources' Node localhost { Script CreateConfigFile { GetScript = { $fileContent = $null if (Test-Path -Path $using:FilePath) { $fileContent = Get-Content -Path $using:FilePath -Raw } return @{ Result = $fileContent } } TestScript = { if (Test-Path -Path $using:FilePath) { $currentContent = Get-Content -Path $using:FilePath -Raw return $currentContent -eq $using:FileContent } return $false } SetScript = { $streamWriter = New-Object -TypeName 'System.IO.StreamWriter' -ArgumentList @($using:FilePath) $streamWriter.WriteLine($using:FileContent) $streamWriter.Close() } } } } ``` -------------------------------- ### Manage registry keys and values with Registry Source: https://context7.com/powershell/psdscresources/llms.txt Handles creation, modification, and removal of registry keys and various value types. ```powershell Configuration RegistryExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Create registry key Registry CreateKey { Key = 'HKLM:\SOFTWARE\MyApplication' ValueName = '' Ensure = 'Present' } # Set string value Registry SetStringValue { Key = 'HKLM:\SOFTWARE\MyApplication' ValueName = 'InstallPath' ValueType = 'String' ValueData = 'C:\Program Files\MyApp' Ensure = 'Present' } # Set DWORD value with force overwrite Registry SetDWordValue { Key = 'HKLM:\SOFTWARE\MyApplication\Settings' ValueName = 'MaxConnections' ValueType = 'DWord' ValueData = '100' Ensure = 'Present' Force = $true } # Set binary value Registry SetBinaryValue { Key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' ValueName = 'CustomFlag' ValueType = 'Binary' ValueData = '0x00' Ensure = 'Present' Force = $true } # Remove registry value Registry RemoveValue { Key = 'HKLM:\SOFTWARE\MyApplication' ValueName = 'DeprecatedSetting' Ensure = 'Absent' } } } ``` -------------------------------- ### Manage Multiple Optional Windows Features with WindowsOptionalFeatureSet Source: https://context7.com/powershell/psdscresources/llms.txt The WindowsOptionalFeatureSet resource simplifies managing multiple optional Windows features with shared configurations. It supports Nano Server and is suitable for enabling or disabling sets of features like Hyper-V or legacy protocols. ```powershell Configuration WindowsOptionalFeatureSetExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Enable multiple optional features WindowsOptionalFeatureSet EnableHyperV { Name = @('Microsoft-Hyper-V-All', 'Microsoft-Hyper-V-Tools-All') Ensure = 'Present' LogPath = 'C:\Logs\HyperV_Enable.log' } # Disable legacy features WindowsOptionalFeatureSet DisableLegacy { Name = @('SMB1Protocol', 'TelnetClient') Ensure = 'Absent' RemoveFilesOnDisable = $true } } } ``` -------------------------------- ### Manage Multiple Processes with ProcessSet Source: https://context7.com/powershell/psdscresources/llms.txt Use the ProcessSet resource to apply common configuration settings to multiple Windows processes simultaneously. ```powershell Configuration ProcessSetExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Start multiple processes ProcessSet StartMonitoringTools { Path = @('C:\Tools\monitor1.exe', 'C:\Tools\monitor2.exe') Ensure = 'Present' StandardOutputPath = 'C:\Logs\monitors_output.log' StandardErrorPath = 'C:\Logs\monitors_error.log' } # Stop multiple processes ProcessSet StopLegacyTools { Path = @('C:\OldTools\tool1.exe', 'C:\OldTools\tool2.exe') Ensure = 'Absent' } } } ``` -------------------------------- ### User Resource Configuration Source: https://github.com/powershell/psdscresources/blob/dev/README.md Defines the parameters for managing local user account states. ```APIDOC ## User Resource ### Description Manages the state of a local user account. ### Parameters #### Request Body - **UserName** (String) - Required (Key) - The account name to ensure. - **Description** (String) - Optional - Description for the user account. - **Disabled** (Boolean) - Optional - Whether the account is disabled (default: false). - **Ensure** (String) - Optional - Ensures feature is {Present | Absent}. - **FullName** (String) - Optional - Full name for the user account. - **Password** (PSCredential) - Optional - Password for the account. - **PasswordChangeNotAllowed** (Boolean) - Optional - Whether user can change password (default: false). - **PasswordChangeRequired** (Boolean) - Optional - Whether user must change password at next sign in (default: true). - **PasswordNeverExpires** (Boolean) - Optional - Whether password expires (default: false). ``` -------------------------------- ### Service Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md The Service resource allows for the management of individual Windows services, including creation, state control, and configuration of startup properties. ```APIDOC ## Service Resource ### Description Manages individual Windows services on a target node. ### Parameters - **Name** (String) - Required (Key) - The service name. - **Ensure** (String) - Optional - Present or Absent. Defaults to Present. - **Path** (String) - Optional - Path to the service executable. - **StartupType** (String) - Optional - Automatic, Disabled, or Manual. - **BuiltInAccount** (String) - Optional - LocalService, LocalSystem, or NetworkService. - **Credential** (PSCredential) - Optional - Credential to run the service. - **DesktopInteract** (Boolean) - Optional - Whether the service can interact with the desktop. Defaults to False. - **State** (String) - Optional - Running, Stopped, or Ignore. Defaults to Running. - **DisplayName** (String) - Optional - The display name of the service. - **Description** (String) - Optional - The description of the service. - **Dependencies** (String[]) - Optional - Array of service dependencies. - **StartupTimeout** (Uint32) - Optional - Timeout in ms. Defaults to 30000. - **TerminateTimeout** (Uint32) - Optional - Timeout in ms. Defaults to 30000. ``` -------------------------------- ### Manage multiple groups with GroupSet Source: https://context7.com/powershell/psdscresources/llms.txt Configures multiple groups with identical membership requirements in a single declaration. ```powershell Configuration GroupSetExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Manage multiple groups with same membership requirements GroupSet DevelopmentGroups { GroupName = @('Developers', 'QATeam', 'DevOps') Ensure = 'Present' MembersToInclude = @('domain\buildservice', 'domain\deployservice') } } } ``` -------------------------------- ### ProcessSet DSC Resource Configuration Source: https://github.com/powershell/psdscresources/blob/dev/README.md Defines the parameters and properties for managing process sets via DSC. ```APIDOC ## ProcessSet DSC Resource ### Description Manages the state of multiple processes, allowing them to be started or stopped, and provides monitoring metrics. ### Parameters #### Key Parameters - **Path** (String[]) - Required - The file paths to the executables of the processes to start or stop. #### Write Parameters - **Credential** (PSCredential) - Optional - The credential of the user account to run the processes under. - **Ensure** (String) - Optional - Specifies whether the processes should be running (Present) or stopped (Absent). - **StandardOutputPath** (String) - Optional - The file path to write standard output. - **StandardErrorPath** (String) - Optional - The file path to write standard error output. - **StandardInputPath** (String) - Optional - The file path to receive standard input. - **WorkingDirectory** (String) - Optional - The working directory for the process. ### Read-Only Properties - **PagedMemorySize** (UInt64) - Amount of paged memory in bytes. - **NonPagedMemorySize** (UInt64) - Amount of nonpaged memory in bytes. - **VirtualMemorySize** (UInt64) - Amount of virtual memory in bytes. - **HandleCount** (SInt32) - Number of handles opened. - **ProcessId** (SInt32) - Unique identifier of the processes. - **ProcessCount** (SInt32) - Number of instances currently running. ``` -------------------------------- ### Import PSDscResources Module in DSC Configuration Source: https://github.com/powershell/psdscresources/blob/dev/README.md Add this line to your DSC configuration to import the PSDscResources module and utilize its updated resources. ```powershell Import-DscResource -ModuleName PSDscResources ``` -------------------------------- ### Configure Multiple Services with ServiceSet Resource Source: https://context7.com/powershell/psdscresources/llms.txt The ServiceSet resource manages multiple Service resources with common settings. It can modify or delete existing services but cannot create new ones. ```powershell Configuration ServiceSetExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Ensure multiple services are running ServiceSet CriticalServices { Name = @('Dhcp', 'MpsSvc', 'Winmgmt') Ensure = 'Present' State = 'Running' StartupType = 'Automatic' } # Configure services to run under LocalService ServiceSet BackgroundServices { Name = @('ServiceA', 'ServiceB', 'ServiceC') Ensure = 'Present' BuiltInAccount = 'LocalService' State = 'Running' } } } ``` -------------------------------- ### Enable or Disable Optional Windows Features Source: https://context7.com/powershell/psdscresources/llms.txt Use the WindowsOptionalFeature resource to enable or disable optional Windows features. This resource works on Nano Server and requires Windows Server 2012 or later, or a Windows client OS with the DISM PowerShell module. ```powershell Configuration WindowsOptionalFeatureExample { Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Enable an optional feature WindowsOptionalFeature EnableContainers { Name = 'Containers' Ensure = 'Present' LogPath = 'C:\Logs\Containers_Enable.log' LogLevel = 'ErrorsAndWarningAndInformation' NoWindowsUpdateCheck = $true } # Disable and remove files for optional feature WindowsOptionalFeature DisableFeature { Name = 'SMB1Protocol' Ensure = 'Absent' RemoveFilesOnDisable = $true } } } ``` -------------------------------- ### Environment Variable Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Configuration parameters for managing environment variables on a target node. ```APIDOC ## Environment Variable Resource ### Description Manages environment variables on a target node, supporting creation, modification, and removal. ### Parameters #### Path Parameters - **Name** (String) - Required - The name of the environment variable to create, modify, or remove. #### Request Body - **Value** (String) - Optional - The desired value for the environment variable. - **Ensure** (String) - Optional - Specifies if the environment variable should exist. { Present | Absent }. - **Path** (Boolean) - Optional - Indicates whether or not the environment variable is a path variable. - **Target** (String[]) - Optional - Indicates the target where the environment variable should be set. { Process | Machine | Process, Machine }. ``` -------------------------------- ### WindowsFeatureSet Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Defines parameters for managing multiple Windows features simultaneously. ```APIDOC ## WindowsFeatureSet Resource ### Description Configures and manages multiple WindowsFeature resources on a target node. ### Parameters #### Request Body - **Name** (String) - Required (Key) - Names of the roles or features to manage. - **Ensure** (String) - Optional - Specifies if features should be {Present | Absent}. - **IncludeAllSubFeature** (Boolean) - Optional - Whether to include subfeatures. - **Credential** (PSCredential) - Optional - Credential for the operation. - **LogPath** (String) - Optional - Custom file path for logging. ### Response #### Read-Only Properties - **DisplayName** (String) - The display names of the retrieved roles or features. ``` -------------------------------- ### Registry Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Manages registry keys and values on a target node. ```APIDOC ## Registry Resource ### Description Provides a mechanism to manage registry keys and values on a target node. ### Method Not Applicable (DSC Resource) ### Endpoint Not Applicable (DSC Resource) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **Key** (String) - Required - The path of the registry key to add, modify, or remove. This path must include the registry hive/drive (e.g. HKEY_LOCAL_MACHINE, HKLM:). - **ValueName** (String) - Required - The name of the registry value. To add or remove a registry key, specify this property as an empty string without specifying ValueType or ValueData. To modify or remove the default value of a registry key, specify this property as an empty string while also specifying ValueType or ValueData. - **Ensure** (String) - Required - Specifies whether or not the registry key or value should exist. To add or modify a registry key or value, set this property to Present. To remove a registry key or value, set this property to Absent. { Present | Absent }. - **ValueData** (String) - Optional - The data the specified registry key value should have as a string or an array of strings (MultiString only). - **ValueType** (String) - Optional - The type the specified registry key value should have. { String | Binary | DWord | QWord | MultiString | ExpandString }. - **Hex** (Boolean) - Optional - Specifies whether or not the specified DWord or QWord registry key data is provided in a hexadecimal format. Not valid for types other than DWord and QWord. The default value is $false. - **Force** (Boolean) - Optional - Specifies whether or not to overwrite the specified registry key value if it already has a value or whether or not to delete a registry key that has subkeys. The default value is $false. ### Request Example ```powershell Registry { Key = "HKLM:\\SOFTWARE\\MyCompany\\MyApplication" ValueName = "Version" Ensure = "Present" ValueData = "1.0.0.0" ValueType = "String" } ``` ### Response #### Success Response (200) None (DSC resources manage state, they do not return data in the traditional sense). #### Response Example None ``` -------------------------------- ### Create or Update a Path Environment Variable Source: https://github.com/powershell/psdscresources/blob/dev/README.md This snippet demonstrates how to create or update an environment variable that is part of the system's path. Set 'Path' to true and provide the value to be appended or replaced. ```powershell Environment { Name = "MyPathVar" Value = "$env:PATH;C:\MyNewPath" Path = $true Ensure = "Present" } ``` -------------------------------- ### Service Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Provides a mechanism to configure and manage Windows services on a target node. ```APIDOC ## Service Resource ### Description Provides a mechanism to configure and manage Windows services on a target node. This resource works on Nano Server. ### Method Not Applicable (DSC Resource) ### Endpoint Not Applicable (DSC Resource) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Service resource parameters are not detailed in the provided text. Please refer to official PowerShell DSC documentation for specific parameters like Name, State, etc.) ### Request Example (Service resource request example is not detailed in the provided text.) ### Response #### Success Response (200) None (DSC resources manage state, they do not return data in the traditional sense). #### Response Example None ``` -------------------------------- ### GroupSet Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Manages multiple local groups, allowing for creation, modification, and removal of groups and their members. ```APIDOC ## GroupSet Resource ### Description Manages multiple local groups on a target node. ### Parameters #### Key Parameters - **GroupName** (String) - Required - The names of the groups to create, modify, or remove. #### Write Parameters - **Ensure** (String) - Optional - Indicates if the groups should exist. { Present | Absent } - **MembersToInclude** (String[]) - Optional - Members to add to the groups. - **MembersToExclude** (String[]) - Optional - Members to remove from the groups. - **Credential** (PSCredential) - Optional - Credential to resolve non-local group members. ``` -------------------------------- ### Manage Local Users with User Resource Source: https://context7.com/powershell/psdscresources/llms.txt The User resource manages local users on a target node, supporting password management, account properties, and user creation/removal. It requires a PSCredential object for password management. ```powershell Configuration UserExample { param ( [Parameter(Mandatory = $true)] [System.Management.Automation.PSCredential] $UserCredential ) Import-DscResource -ModuleName 'PSDscResources' Node localhost { # Create a new local user User CreateUser { UserName = 'AppServiceAccount' Ensure = 'Present' Password = $UserCredential FullName = 'Application Service Account' Description = 'Service account for running application' PasswordNeverExpires = $true PasswordChangeNotAllowed = $true Disabled = $false } # Ensure a user does not exist User RemoveUser { UserName = 'TemporaryUser' Ensure = 'Absent' } } } # Usage: ``` -------------------------------- ### Script Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Provides a mechanism to run PowerShell script blocks on a target node. ```APIDOC ## Script Resource ### Description Provides a mechanism to run PowerShell script blocks on a target node. This resource works on Nano Server. ### Method Not Applicable (DSC Resource) ### Endpoint Not Applicable (DSC Resource) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **GetScript** (String) - Required - A string that can be used to create a PowerShell script block that retrieves the current state of the resource. This script block runs when the Get-DscConfiguration cmdlet is called. This script block should return a hash table containing one key named Result with a string value. - **SetScript** (String) - Required - A string that can be used to create a PowerShell script block that sets the resource to the desired state. This script block runs conditionally when the Start-DscConfiguration cmdlet is called. The TestScript script block will run first. If the TestScript block returns False, this script block will run. If the TestScript block returns True, this script block will not run. This script block should not return. - **TestScript** (String) - Required - A string that can be used to create a PowerShell script block that validates whether or not the resource is in the desired state. This script block runs when the Start-DscConfiguration cmdlet is called or when the Test-DscConfiguration cmdlet is called. This script block should return a boolean with True meaning that the resource is in the desired state and False meaning that the resource is not in the desired state. - **Credential** (PSCredential) - Optional - The credential of the user account to run the script under if needed. ### Request Example ```powershell Script { GetScript = @" $Result = @{ Result = (Get-Content -Path 'C:\Temp\TestFile.txt') } return $Result "@ SetScript = @" Set-Content -Path 'C:\Temp\TestFile.txt' -Value 'Hello World!' "@ TestScript = @" return (Test-Path -Path 'C:\Temp\TestFile.txt') "@ } ``` ### Response #### Success Response (200) - **Result** (String) - The result from the GetScript script block. #### Response Example ```json { "Result": "Hello World!" } ``` ``` -------------------------------- ### WindowsOptionalFeatureSet Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Provides a mechanism to configure and manage multiple WindowsOptionalFeature resources on a target node. ```APIDOC ## WindowsOptionalFeatureSet ### Description Provides a mechanism to configure and manage multiple WindowsOptionalFeature resources on a target node. This resource works on Nano Server. ### Parameters #### Key Parameters - **Name** (String[]) - Required - The names of the Windows optional features to enable or disable. #### Write Parameters - **Ensure** (String) - Optional - Specifies whether the Windows optional features should be enabled or disabled. { Present | Absent }. - **RemoveFilesOnDisable** (Boolean) - Optional - Specifies whether or not to remove the files associated with the Windows optional features when they are disabled. - **NoWindowsUpdateCheck** (Boolean) - Optional - Specifies whether or not DISM should contact Windows Update (WU) when searching for the source files. - **LogPath** (String) - Optional - The file path to which to log the operation. - **LogLevel** (String) - Optional - The level of detail to include in the log. { ErrorsOnly | ErrorsAndWarning | ErrorsAndWarningAndInformation }. ``` -------------------------------- ### ServiceSet Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md The ServiceSet resource provides a mechanism to configure and manage multiple existing services with common settings. ```APIDOC ## ServiceSet Resource ### Description Manages multiple existing services simultaneously. Note: This resource cannot create new services. ### Parameters - **Name** (String[]) - Required (Key) - Names of the services to modify or delete. - **Ensure** (String) - Optional - Present or Absent. - **BuiltInAccount** (String) - Optional - LocalService, LocalSystem, or NetworkService. - **Credential** (PSCredential) - Optional - Credential to run the services. - **StartupType** (String) - Optional - Automatic, Disabled, or Manual. - **State** (String) - Optional - Running, Stopped, or Ignore. ``` -------------------------------- ### Group Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Configuration parameters for managing local groups on a target node. ```APIDOC ## Group Resource ### Description Provides a mechanism to manage local groups on a target node, including adding members, removing members, and setting descriptions. ### Parameters #### Path Parameters - **GroupName** (String) - Required - The name of the group to create, modify, or remove. #### Request Body - **Ensure** (String) - Optional - Indicates if the group should exist or not. { Present | Absent }. - **Description** (String) - Optional - The description the group should have. - **Members** (String[]) - Optional - The members the group should have. Replaces all current members. - **MembersToInclude** (String[]) - Optional - Members to add to the group. - **MembersToExclude** (String[]) - Optional - Members to remove from the group. - **Credential** (PSCredential) - Optional - A credential to resolve non-local group members. ``` -------------------------------- ### Archive DSC Resource Configuration Source: https://github.com/powershell/psdscresources/blob/dev/README.md Defines the parameters for managing archive files using the Archive DSC resource. ```APIDOC ## Archive DSC Resource ### Description Manages the expansion or removal of archive files at a specified destination. ### Parameters #### Path Parameters - **Path** (String) - Required - The path to the archive file. - **Destination** (String) - Required - The path where the archive should be expanded to or removed from. #### Request Body - **Ensure** (String) - Optional - Specifies if content should exist (Present) or be removed (Absent). Default is Present. - **Validate** (Boolean) - Optional - Whether to validate files using checksums. Default is false. - **Checksum** (String) - Optional - Method to validate files (ModifiedDate, CreatedDate, SHA-1, SHA-256, SHA-512). Default is ModifiedDate. - **Credential** (PSCredential) - Optional - User account credentials for accessing paths. - **Force** (Boolean) - Optional - Whether to overwrite existing files at the destination. Default is false. ``` -------------------------------- ### WindowsOptionalFeature Resource Source: https://github.com/powershell/psdscresources/blob/dev/README.md Provides a mechanism to enable or disable optional features on a target node. ```APIDOC ## WindowsOptionalFeature ### Description Provides a mechanism to enable or disable optional features on a target node. This resource works on Nano Server. ### Parameters #### Key Parameters - **Name** (String) - Required - The name of the Windows optional feature to enable or disable. #### Write Parameters - **Ensure** (String) - Optional - Specifies whether the feature should be enabled or disabled. { Present | Absent }. Default is Present. - **RemoveFilesOnDisable** (Boolean) - Optional - Specifies that all files associated with the feature should be removed if the feature is being disabled. - **NoWindowsUpdateCheck** (Boolean) - Optional - Specifies whether or not DISM contacts Windows Update (WU) when searching for the source files. - **LogPath** (String) - Optional - The path to the log file. - **LogLevel** (String) - Optional - The maximum output level to show in the log. { ErrorsOnly | ErrorsAndWarning | ErrorsAndWarningAndInformation }. Default is ErrorsAndWarningAndInformation. ### Read-Only Properties - **CustomProperties** (String[]) - The custom properties retrieved from the Windows optional feature. - **Description** (String) - The description retrieved from the Windows optional feature. - **DisplayName** (String) - The display name retrieved from the Windows optional feature. ``` -------------------------------- ### Remove an Environment Variable Source: https://github.com/powershell/psdscresources/blob/dev/README.md Use this configuration to remove an environment variable. Set 'Ensure' to 'Absent' and provide the 'Name' of the variable to be removed. ```powershell Environment { Name = "MyEnvVarToRemove" Ensure = "Absent" } ``` -------------------------------- ### Remove Members from a Group Source: https://github.com/powershell/psdscresources/blob/dev/README.md This snippet demonstrates how to remove specific members from a local group without affecting other members. Use 'MembersToExclude' to specify the members to be removed. ```powershell Group { GroupName = "MyGroup" MembersToExclude = @("DOMAIN\User1") Ensure = "Present" } ``` -------------------------------- ### Create a Non-Path Environment Variable Source: https://github.com/powershell/psdscresources/blob/dev/README.md Use this snippet to create a new environment variable that is not a path variable. Ensure the 'Name' and 'Value' parameters are set to your desired environment variable name and value. ```powershell Environment { Name = "MyEnvVar" Value = "MyValue" Ensure = "Present" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.