zoukankan      html  css  js  c++  java
  • DSC配置

    #配置Remote Desktop Services服务为 自启动,并运行

    Configuration Myservice
    {
    # A Configuration block can have zero or more Node blocks
    Node "localhost"
    {
    Service ServiceExample
    {
    Name = "TermService"
    StartupType = "Automatic"
    State = "Running"
    }
    }
    }

    Myservice

    Start-DscConfiguration -wait -Verbose -Path .Myservice

    =============================================

    #配置目录下文件

    Configuration MyWebConfig
    {
    # A Configuration block can have zero or more Node blocks
    Node "localhost"
    {
    # File is a built-in resource you can use to manage files and directories
    # This example ensures files from the source directory are present in the destination directory
    File MyFileExample
    {
    Ensure = "Present" # You can also set Ensure to "Absent"
    Type = "Directory“ # Default is “File”
    Recurse = $true
    #SourcePath = $WebsiteFilePath # This is a path that has web files
    SourcePath = "C:inetpubwwwroot"
    DestinationPath = "C:inetpubwwwrootdes" # The path where we want to ensure the web files are present
    #DependsOn = "[WindowsFeature]MyRoleExample" # This ensures that MyRoleExample completes successfully before this block runs
    }
    Log AfterDirectoryCopy
    {
    # The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
    Message = "Finished running the file resource with ID DirectoryCopy"
    DependsOn = "[File]MyFileExample" # This means run "DirectoryCopy" first.
    }
    }
    }

    MyWebConfig

    Start-DscConfiguration -wait -Verbose -Path .MyWebConfig

    #带有参数的DSCConfiguration

    Configuration MyParametrizedConfiguration
    {
        # Parameters are optional
        param ($MyTargetNodeName, $MyGroupName)
    
        Node $MyTargetNodeName
        {
            # Group is a built-in resource that you can use to manage local Windows groups
            # This example ensures the existence of a group with the name specified by $MyGroupName
            Group MyGroupExample
            {
                Ensure = "Present" # Checks whether a group by this GroupName already exists and creates it if it does not
                Name = $MyGroupName
            }
        }
    }  
    MyParametrizedConfiguration -MyTargetNodeName "Server001" -MyGroupName "TestGroup" 

    Start-DSCConfiguration MyParametrizedConfiguration -wait

    PowerShell内置DSC资源:http://technet.microsoft.com/en-us/library/dn282120.aspx

    =======================================================================

    configuration dsc_service
    {
    param ($servicename)
    Log dsc_service_log
    {Message = "It's a message from DSC:Servicename = $servicename"}

    Service ServiceExample
    {
    Name = $servicename
    StartupType = "Automatic"
    State = "Running"
    }
    }

    #查看已定义的ConfigurationType
    get-command -CommandType Configuration

    get-command -CommandType Configuration|Remove-Item (删除)

     启用配置:

    dsc_service -servicename Spooler(如果没有定义参数的话,则不需要加参数选项),默认配置文件保存到当前目录下,生成后可以将其移走

    将配置推送到目标计算机:

    Start-Dscconfiguration -Computername localhost .dsc_service (由于未在配置中定义目标节点,所以此处使用computername参数作为目标计算机)

    -Wait:等待配置完成

    -Verbose:输出详细信息流到窗口

    查看当前计算机已有的DSC配置(只有start-dscconfiguration之后才能get-dscconfiguration,此处为Message说明)

    Get-DscConfiguration

    查找DSC可用资源及其相应参数:

    Get-DscResource

    (Get-DscResource -Name File).properties|ft -Wrap

    The Restore-DscConfiguration cmdlet restores the previous configuration for the node, if a previous configuration exists. Specify computers by using Common Information Model (CIM) sessions. If you do not specify a target computer, the cmdlet restores the configuration of the local computer.

    $Session = New-CimSession –ComputerName "Server01" –Credential ACCOUNTSPattiFuller
    Restore-DscConfiguration -CimSession $Session
  • 相关阅读:
    【JavaScript】关于javascript原型的深入理解
    【JavaScript】关于JS中的constructor与prototype
    【JavaScript】关于prototype
    【JavaScript】重温Javascript继承机制
    【JavaScript】新浪微博ajax请求后改变地址栏url,但页面不跳转的方案解析
    【JavaScript】JavaScript函数的参数
    【JavaScript】页面加载性能优化
    HTML5 修改浏览器url而不刷新页面
    【339】matplotlib based on python3
    【338】Pandas.DataFrame
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/3573963.html
Copyright © 2011-2022 走看看