快速上手:Powershell執行DSC指令碼
阿新 • • 發佈:2021-01-11
技術標籤:個人心德powershell.Net後端
快速上手:Windows—Powershell執行DSC指令碼
1. DSC示例指令碼如下(在本地儲存為:ProvisionImageForTest .ps1):
Configuration ProvisionImageForTest { # Import the module that contains the resources we're using. Import-DscResource -ModuleName PSDesiredStateConfiguration # The Node statement specifies which targets this configuration will be applied to. Node localhost { # The first resource block ensures that the Web-Server (IIS) feature is enabled. WindowsFeature WebServer { Ensure = "Present" Name = "Web-Server" } # The second resource block ensures that the website content copied to the website root folder. File WebsiteContent { Ensure = 'Present' SourcePath = 'F:\****\VM\DSC\test\test.htm' DestinationPath = 'F:\****\VM\DSC\test\wwwroot' } } }
2. powershell以管理員命令執行,並切換到該檔案的同級目錄,執行以下命令以生成mof編譯檔案(localhost.mof):
. .\ProvisionImageForTest.ps1
ProvisionImageForTest
執行結果如下:
3. 執行編譯檔案: localhost.mof, 完成對DSC指令碼的執行
需要將本機Windows配置為接收PowerShell遠端命令,命令如下(如果DSC指令碼檔案中Node節點指定的目標節點不是本機,請在目標節點的機器上執行此命令):
Set-WsManQuickConfig -Force```
Powershell切換到該mof編譯檔案的同級目錄中,執行一下命令即可:
Start-DscConfiguration ..\ProvisionImageForTest
執行結果: