内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

PowershellDSC5.0-資源的使用

Powershell DSC 自帶了一些常見的資源。如果需要新的,可以下載安裝 DSC Resource Kit 10或者從Powershell Gallery下載。

10年積累的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有前進(jìn)免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

比如說查看當(dāng)前已經(jīng)安裝了的資源

PS C:\Windows\system32> Get-DscResource
ImplementedAs   Name                      ModuleName                     Version    Properties                                        
-------------   ----                      ----------                     -------    ----------                                        
Binary          File                                                                {DestinationPath, Attributes, Checksum, Content...
PowerShell      Archive                   PSDesiredStateConfiguration    1.1        {Destination, Path, Checksum, Credential...}      
PowerShell      Environment               PSDesiredStateConfiguration    1.1        {Name, DependsOn, Ensure, Path...}                
PowerShell      Group                     PSDesiredStateConfiguration    1.1        {GroupName, Credential, DependsOn, Description...}
Binary          Log                       PSDesiredStateConfiguration    1.1        {Message, DependsOn, PsDscRunAsCredential}        
PowerShell      Package                   PSDesiredStateConfiguration    1.1        {Name, Path, ProductId, Arguments...}             
PowerShell      Registry                  PSDesiredStateConfiguration    1.1        {Key, ValueName, DependsOn, Ensure...}            
PowerShell      Script                    PSDesiredStateConfiguration    1.1        {GetScript, SetScript, TestScript, Credential...} 
PowerShell      Service                   PSDesiredStateConfiguration    1.1        {Name, BuiltInAccount, Credential, Dependencies...
PowerShell      User                      PSDesiredStateConfiguration    1.1        {UserName, DependsOn, Description, Disabled...}   
PowerShell      WaitForAll                PSDesiredStateConfiguration    1.1        {NodeName, ResourceName, DependsOn, PsDscRunAsC...
PowerShell      WaitForAny                PSDesiredStateConfiguration    1.1        {NodeName, ResourceName, DependsOn, PsDscRunAsC...
PowerShell      WaitForSome               PSDesiredStateConfiguration    1.1        {NodeCount, NodeName, ResourceName, DependsOn...} 
PowerShell      WindowsFeature            PSDesiredStateConfiguration    1.1        {Name, Credential, DependsOn, Ensure...}          
PowerShell      WindowsOptionalFeature    PSDesiredStateConfiguration    1.1        {Name, DependsOn, Ensure, LogLevel...}            
PowerShell      WindowsProcess            PSDesiredStateConfiguration    1.1        {Arguments, Path, Credential, DependsOn...}       
PowerShell      xArchive                  xPSDesiredStateConfiguration   3.5.0.0    {Destination, Path, CompressionLevel, DependsOn...
PowerShell      xDSCWebService            xPSDesiredStateConfiguration   3.5.0.0    {CertificateThumbPrint, EndpointName, AcceptSel...
PowerShell      xGroup                    xPSDesiredStateConfiguration   3.5.0.0    {GroupName, Credential, DependsOn, Description...}
PowerShell      xPackage                  xPSDesiredStateConfiguration   3.5.0.0    {Name, Path, ProductId, Arguments...}             
PowerShell      xPSEndpoint               xPSDesiredStateConfiguration   3.5.0.0    {Name, AccessMode, DependsOn, Ensure...}          
PowerShell      xRemoteFile               xPSDesiredStateConfiguration   3.5.0.0    {DestinationPath, Uri, Credential, DependsOn...}  
PowerShell      xService                  xPSDesiredStateConfiguration   3.5.0.0    {Name, BuiltInAccount, Credential, Dependencies...
PowerShell      xWindowsOptionalFeature   xPSDesiredStateConfiguration   3.5.0.0    {Name, DependsOn, Ensure, LogLevel...}            
PowerShell      xWindowsProcess           xPSDesiredStateConfiguration   3.5.0.0    {Arguments, Path, Credential, DependsOn...}

下面是一些常見的例子:

  1. 拷貝文件 資源叫做 File

configuration TestFile {
    Node sydittest {
        File ZipFile {
            Ensure = "Present" 
            Type = "Directory“ # Default is “File”
            Force = $True
            Recurse = $True
            SourcePath = '\\sydit01\test'
            DestinationPath = 'C:\Downloads'  # On Sydittest
        }
    }
}
TestFile -OutputPath c:\DSC\Mod5Config
Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -force

Powershell DSC 5.0 - 資源的使用

查看該zip文件已經(jīng)拷貝了

Powershell DSC 5.0 - 資源的使用

2.解壓zip文件,資源叫做 Archive

configuration TestArchive {
    Node sydittest {
        Archive Unzip{
            Destination = 'C:\unzip'
            Path = 'c:\downloads\temp.zip'
            Checksum = 'SHA-256'
            Validate = $true
            Force = $true
            Ensure = 'Present'
        }
    }
}
TestArchive -OutputPath c:\DSC\Mod5Config
Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -Force

Powershell DSC 5.0 - 資源的使用

該文件已經(jīng)解壓到指定目錄

Powershell DSC 5.0 - 資源的使用

3. 創(chuàng)建環(huán)境變量 資源叫做Environment

configuration TestEnvVar {
    Node sydittest {
        Environment NewVar{
            Name = 'MYNEWVAR'
            Value = 'Value to store'
            Ensure = 'Present'
        }
    }
}
TestEnvVar -OutputPath c:\DSC\Mod5Config

Powershell DSC 5.0 - 資源的使用

確認(rèn)該環(huán)境變量已經(jīng)創(chuàng)建

Powershell DSC 5.0 - 資源的使用

4.創(chuàng)建本地用戶 資源是User

這個(gè)是幾個(gè)資源里面相對麻煩的一個(gè),因?yàn)槟J(rèn)傳遞的是明文,他不會允許你推送的,我需要明確告訴他允許明文。

configuration TestUser
{
    param
    ( 
        [PSCredential]$Credential
    )
    node sydittest
    {    
        User TestUser
        {
            UserName = $Credential.UserName
            Ensure = 'Present'
            Password = $Credential
            Description = 'User created by DSC'
            PasswordNeverExpires = $true
            PasswordChangeNotAllowed = $true
        }
    }
}
$ConfigData = @{   
    AllNodes = @(        
        @{     
            NodeName = 'sydittest'
            PSDscAllowPlainTextPassword=$true
        } 
    )  
} 
TestUser -ConfigurationData $ConfigData -Credential (Get-Credential) -OutputPath c:\DSC\Mod5Config

可以看見是明文發(fā)送的,如果是生產(chǎn)環(huán)境,需要用證書加密的才行。

Powershell DSC 5.0 - 資源的使用

推送出去

Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -force

Powershell DSC 5.0 - 資源的使用

可以看見用戶已經(jīng)創(chuàng)建了

Powershell DSC 5.0 - 資源的使用

5.創(chuàng)建本地組 資源 Group

configuration TestGroup {
    Node sydittest {
        Group CreateGroup {
            Ensure = 'Present'
            GroupName = 'TestGroup'
            Description = 'This is a DSC test group'
            Members = 'administrator'
        } 
        
    }
}
TestGroup -OutputPath c:\DSC\Mod5Config
Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -force

Powershell DSC 5.0 - 資源的使用

6.創(chuàng)建注冊表鍵 資源 Registry

configuration TestRegistry {
    Node sydittest {
        Registry CreateReg {
            Key = 'HKEY_Local_Machine\Software\DSCTest'
            ValueName = 'DSCTestGood'
            ValueType = 'string'
            ValueData = 'True'
        } 
    }
}
Testregistry -OutputPath c:\DSC\Mod5Config
Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -force

Powershell DSC 5.0 - 資源的使用

確認(rèn)成功創(chuàng)建

Powershell DSC 5.0 - 資源的使用

7. 創(chuàng)建進(jìn)程(運(yùn)行某個(gè)程序) 資源是 Windowsprocess

configuration TestProcess {
    Node sydittest {
        WindowsProcess CreateNotepad {
            Path = 'notepad.exe'
            Arguments = ''
        } 
        WindowsProcess CreatePaint {
            Path = 'mspaint.exe'
            Arguments = ''
        }
    }
}
TestProcess -OutputPath c:\DSC\Mod5Config
Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -force

確認(rèn)

Powershell DSC 5.0 - 資源的使用

8. 更改服務(wù)的狀態(tài)

configuration TestService {
    Node sydittest {
        Service StartAudio {
            Name = 'Audiosrv'
            State = 'Running'
            StartupType = 'Automatic'
        } 
    }
}
TestService -OutputPath c:\DSC\Mod5Config
Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -force

更改前

Powershell DSC 5.0 - 資源的使用

更改

Powershell DSC 5.0 - 資源的使用

更改后

Powershell DSC 5.0 - 資源的使用

9. 腳本資源

這個(gè)是當(dāng)現(xiàn)有的資源都無法滿足需求的時(shí)候,可以進(jìn)行自定義資源。里面有3個(gè)子模塊,test,set,get

首先通過 test 判斷狀態(tài),返回一個(gè)boolean值,如果是true,忽略;如果是false,那么在set里面進(jìn)行處理;相當(dāng)于于一個(gè)if else的判斷語句。get可以通過getdsc的命令獲取當(dāng)前狀態(tài)

下面的例子是判斷如果bits服務(wù)開啟,那么關(guān)閉

configuration TestScript {
    Node sydittest {
        Script TestScript {
            GetScript = {
                @{
                    GetScript = $GetScript
                    SetScript = $setScript
                    TestScript = $TestScript
                    Result = (Get-Service -name bits).status
                }           
            }
            SetScript = {
                stop-Service -name bits
            }
            TestScript = {
            
                $Status=(Get-service -name bits).status
                $Status -eq 'stopped'
            }
        }
        
    }
}
Testscript -OutputPath c:\DSC\Mod5Config
Start-DscConfiguration -computername sydittest -Path c:\dsc\Mod5Config -Wait -Verbose -force

Powershell DSC 5.0 - 資源的使用

Powershell DSC 5.0 - 資源的使用

分享名稱:PowershellDSC5.0-資源的使用
文章源于:http://www.rwnh.cn/article0/gjhiio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管品牌網(wǎng)站制作、全網(wǎng)營銷推廣品牌網(wǎng)站設(shè)計(jì)、、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營
张家川| 开封县| 盐亭县| 喀什市| 乐亭县| 慈溪市| 汉沽区| 宜章县| 平安县| 嘉善县| 松潘县| 曲阜市| 高碑店市| 台前县| 通江县| 翁源县| 平凉市| 铜川市| 彭州市| 城步| 永城市| 洛浦县| 广河县| 龙游县| 武安市| 大足县| 南皮县| 凤城市| 高要市| 自治县| 镇原县| 新沂市| 尖扎县| 堆龙德庆县| 仙游县| 汉川市| 阳山县| 苍梧县| 西宁市| 英德市| 阿瓦提县|