Powershell DSC and WMF 5.0 Preview-push modes

Source: Internet
Author: User
Tags powershell dsc

Beans recently began learning PowerShell DSC.

There are many related courses on MVA, and the latest introductory courses are based on WMF 5.0 Preview.

https://www.microsoftvirtualacademy.com/en-US/training-courses/ getting-started-with-powershell-desired-state-configuration-dsc--8672?l=yzhpimg1_7204984382

After 5.0, Microsoft has made a lot of improvements in this piece of DSC. For example, Microsoft has set up a central repository website https://www.powershellgallery.com/so users can download the required PowerShell modules directly. Can see that the site currently provides more than 800 modules can be downloaded;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/7D/wKiom1X_fjGCxrGIAARmHB-OItY021.jpg "title=" 15.PNG "Style=" Float:none; "alt=" wkiom1x_fjgcxrgiaarmhb-oity021.jpg "/>

The download is simple and can be downloaded by executing save-module on a machine with WMF 5.0 preview installed, and the Install-modue can be installed directly. For security reasons, it is generally recommended that you use Save-module to confirm the script before performing the installation.

Like what

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/7D/wKiom1X_fvWC1TMBAAIht5AtKNA727.jpg "title=" 16.PNG "alt=" Wkiom1x_fvwc1tmbaaiht5atkna727.jpg "/>

Simply familiarize yourself with the PowerShell gallery and start getting to the point.

Unlike traditional scripts, Powershell DSC does not need to tell the system the exact installation and configuration steps, just tell the system what kind of state you expect, and then let us know where to get the corresponding resources to implement this state, Local configuration The manager will automatically process it.

As an introductory course, you first learn the most basic push mode, the basic process is simple, the configuration LCM Meta.mof file, this meta file will tell the LCM how often to detect a state change, how to handle it, and so on, and then generate a MOF profile for the client, telling him the required state and resources, and finally pushing it to the client via Start-dscconfiguration.

The lab environment, two Windows R2 servers, have the WMF 5.0 Preview version installed. Beans need to automatically install an IIS as a test

First look at the default LCM configuration of the client (sydittest), his mode is applyandmonitor, there is a problem notifying the administrator, but will not automatically correct

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/7B/wKioL1X_gGPRbpdAAAEiCAbhlCw975.jpg "style=" float: none; "title=" 1.PNG "alt=" Wkiol1x_ggprbpdaaaeicabhlcw975.jpg "/>

We need to create a new LCM meta-configuration file and change the schema to Applyandautocorrect, as shown below.

Attention! Here is the new format for 5.0

[Dsclocalconfigurationmanager ()] Configuration Lcmpush {Node $Computername {settings{allowmoduleoverwrite = $True ConfigurationMode = ' Applyandau Tocorrect ' RefreshMode = ' Push '}} $Computername = ' sydittest ' # Create the Computer.Meta.Mof in Folderlcmpush-outputpath C : \DSC\LCM

The old format of Powershell 4.0 is as follows, and of course both are working

Configuration Lcmpush {Node $Computername {localconfigurationmanager{allowmoduleoverwrite = $True configurationm Ode = ' applyandautocorrect ' RefreshMode = ' Push '}} $Computername = ' sydittest1 ' # Create the Computer.Meta.Mof in FOLDERLCM Push-outputpath C:\DSC\LCM

Execute script, generate Meta.mof file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/7B/wKioL1X_iCLgggu9AAB-12NiFMY879.jpg "title=" 17.PNG "alt=" Wkiol1x_iclgggu9aab-12nifmy879.jpg "/>

Then push the generated meta.mof file to the client

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/7D/wKiom1X_fibiom2vAALs6xCgs38129.jpg "style=" float: none; "title=" 2.PNG "alt=" Wkiom1x_fibiom2vaals6xcgs38129.jpg "/>

Wait a moment and discover that the state pattern has changed.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/7B/wKioL1X_gGSjCEkHAAIiu2KU42Q109.jpg "style=" float: none; "title=" 3.PNG "alt=" Wkiol1x_ggsjcekhaaiiu2ku42q109.jpg "/>

The client views the generated configuration file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/7D/wKiom1X_fiiDdZk2AAHjgAqBgPw538.jpg "style=" float: none; "title=" 4.PNG "alt=" Wkiom1x_fiiddzk2aahjgaqbgpw538.jpg "/>

The meta configuration of the LCM is ready, so let's look at the resources (Resource)

Currently I have installed the following resources, the following experiments need to use windowsfeature this resource

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/7B/wKioL1X_gGfxAZY-AASYTmpYgy8739.jpg "style=" float: none; "title=" 5.PNG "alt=" Wkiol1x_ggfxazy-aasytmpygy8739.jpg "/>

You can see what the syntax structure for invoking the resource is

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/7D/wKiom1X_firxJOj2AAD_AhkWnC4460.jpg "style=" float: none; "title=" 6.PNG "alt=" Wkiom1x_firxjoj2aad_ahkwnc4460.jpg "/>

Create a SIMPLECONFIG.PS1 script, as shown below, he will generate a sydittest.mof file, this is the configuration file we need, and finally push it to the client

Configuration ConfigName {Node $ComputerName {windowsfeature iis{Name = ' Web-server ' En sure = ' Present '}} $computername = ' sydittest ' Configname-outputpath c:\DSC\Config

Execute it and generate the MOF file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/7B/wKioL1X_gGjCV-DWAAEtiOQl-do965.jpg "style=" float: none; "title=" 7.PNG "alt=" Wkiol1x_ggjcv-dwaaetioql-do965.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/7B/wKioL1X_iFmySz3LAABKah9T2r4316.jpg "title=" 18.PNG "alt=" Wkiol1x_ifmysz3laabkah9t2r4316.jpg "/>

Before you push to the client, test IIS before you see the installation

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/7D/wKiom1X_fivAbaFgAAE2ZWyxc3c202.jpg "style=" float: none; "title=" 8.PNG "alt=" Wkiom1x_fivabafgaae2zwyxc3c202.jpg "/>

Push to the client, note that-verbose will show the specific steps;-wait will be executed at the foreground.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/7D/wKiom1X_fizQ5KqDAAUX4f4m1DI080.jpg "style=" float: none; "title=" 9.PNG "alt=" Wkiom1x_fizq5kqdaaux4f4m1di080.jpg "/>

Test it and find that IIS is automatically installed

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/7B/wKioL1X_gGrxssTXAAIBxsOrAo8535.jpg "style=" float: none; "title=" 10.PNG "alt=" Wkiol1x_ggrxsstxaaibxsorao8535.jpg "/>

The client confirms that it has already installed

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/7D/wKiom1X_fi6xw-0xAACZcc2pjnk399.jpg "style=" float: none; "title=" 11.PNG "alt=" Wkiom1x_fi6xw-0xaaczcc2pjnk399.jpg "/>

Try to manually delete and ask to restart after deleting

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/7D/wKiom1X_fjCB6UnVAADZQkjYrTc011.jpg "style=" float: none; "title=" 13.PNG "alt=" Wkiom1x_fjcb6unvaadzqkjyrtc011.jpg "/>

After restarting, we found that IIS was installed automatically and the experiment was successful!

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/7B/wKioL1X_gG2DcAfpAACPYx_zvag916.jpg "style=" float: none; "title=" 14.PNG "alt=" Wkiol1x_gg2dcafpaacpyx_zvag916.jpg "/>

This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1696697

Powershell DSC and WMF 5.0 Preview-push modes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.