21. PowerShell Desired State Configuration (DSC) How-To for Beginners (Push Model)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on YouTube do you hear from signal Warren comm a tonight we're going to talk about power shells desired state configuration manager so what this thing is is it's a powerful management platform outside of the typical window or Microsoft based enterprise tools such as SCCM and all that kind of stuff very powerful you can do a lot of stuff with it I'm just going to go over the basics it's available in PowerShell v4 greater so ships natively with server to k12 r2 in Windows 8.1 my box is currently 5.1 some run Windows 10 Pro it is declarative model so this kind of it's a little bit different than typical PowerShell commands look and I'll show you an example of that so in our typical powershell if I wanted to say check make sure a service is running and if a service is not running I'm going to start it so this is one way I would do it in a regular powershell command i'm going to get the service i'm going to look for the service MS exchange transport because my transport service needs to be started for exchange to work i want to look for it in a running status so then I use this if statement if it's not in a running status I'm going to go ahead and start it so what declared a model is in desired state configuration manager you basically tell DSC what you want and it figures out the how so here in this little script you can tell it's pretty simple I'm going to use the service provider or not provider resource service resource and this comes built in with DSC I'm going to tell the name of the service and I'm going to just tell it I want to always be on a running status so it's that simple a little different than a regular powershell but what you can have is pretty pretty simple so DSC uses the workflow engine and on the target knows the local configuration manager is the engine that runs in the background that actually makes the magic happen very good for scaled management you can do it a couple different ways push or pull architecture I'm going to talk about the push tonight because it's the easiest and it's the less you don't have to have another server a pull architecture which I'll probably do in another video you'll have you have to stand up a server with DSC feature installed if you want more information there's a link on MSDN that you can get a little more information on so to kind of understand what DSC is doing a little bit of terminology you need to understand so DSC resource you can think of that as a PowerShell module and it so this is a basic Windows 10 box with are set to little installed so you should get the same kind of output here so if I do get DSC resource so this is going to give me a list of all the default resources that are included with DSC and there you see the service which is the one we'll be using time but there's a file environment group there's all kinds of resources and you can get more at powershell gallery comm so I want to find all my commands that are available in DSC I can run this little commandment here get command dash down DSC star and there are on my built-in DSP functions again this is out of the box DSC configuration doesn't include all the bells and whistles that you can get off of PowerShell gallery or other places so let's say I want to choose a particular resource so I'm going to this I'm going to look at the file and then I'm going to see what I can configure here so this is what I configure a file attribute the checksum credentials I can run resources in DSC and make them dependent upon one another so I can run them in a certain order which I'll probably expand on this video and show you how to do that with all of the exchange services at some point all right so the configuration is done on the target via ma file and I'll go through how you create the MA files let's talk about the notes the nodes are simply your target machines and again I talked about alcm already so this is kind of the way I do DSC first I want to define the problem or what I want to monitor in this case I want to monitor an exchange service to make sure it's running then I'm going to create the LCM config now this is an optional step you don't necessarily have to do this unless your LCM config is outside of the default and I'll show you the default here in a second so you're going to create your configuration optimally you want to test your configuration before you deploy it in a production environment then you basically push it to the nodes and then you're in a monitor state so you can test DSC configuration at certain intervals manually or you set up as a job to do it and okay so push architecture this is basically what we're looking at time so I can take any client laptop running power show v4 or above create my configuration here and push it to any number of clients on my network it's really that simple all right so let's get into creating an actual configuration you clear the screen all right so here is my basic calcium configuration so in order to create the ma file I want to load this function into memory so I'm going to highlight it here there you go now I'm going to generate my ma file calling my function with computer name and then the name of whatever gear I want to push it to so in this case I'm going to do it with my exchange server which is exch that's the actual computer name if I want to do more than one I can comma separate them dc1 or I could import them through a text file okay so it says my MA file has been created now let's look here so I'm in C scripts my LCM config which is my function name let's look at this mod file and here you can say it created it for the exchange server created by me on this date and here is the configuration that we want to make okay so let's check the default configuration on the exchange server right now you'll see that the configuration mode frequency is set to 15 minutes so let's push this too big so I'm going to use set - DC local configuration manager commandant and give it a path of LC and config so that's the LCM config folder and C scripts okay so supposedly my configuration has been pushed to the exchange server so let's take a look at it again and now you can see that the configuration mode frequency in minutes has changed to 30 so LCM configurations is that simple all right so let's get to the nuts and bolts of it as far as creating a configuration for the exchange server so it's very similar to the way you today LCM configuration I'm going to call the configuration create a function using the configuration command I'm going to call it exchange service same thing here I'm going to ask it for a parameter of a computer name it's going to default to localhost my target node to the computer name and this is what I'm going to do on each target so I want to use the service resource I want to make sure this service is in a running state so to generate my configuration ma file I'm just going to call my function using the computer name parameter and this is the name of my exchange server and the same thing here applies if I wanted to do this to more than one computer I could comma separate computer names or import them from a CSV file or text file however you want to do it all right so let's generate this okay it's loading so it says it is created and it's going to begin C scripts exchange service so there is our ma file all right so the ma file looks very much the same as LCM config so there's the target who created it what date and this is basically what I want to do I want this image to exchange transport service and our running state we've generated our MA so we're going to use start DSC configuration give it a path of exchange service which is on C scripts we're going to use the - wait and verbose which is going to tell you basically how it's going through the configuration process so this is going to push the configuration all right DSC configuration complete so now let's check the configuration and this tells us that there's a configuration on there that starts - MS exchange transport service and a running state okay so detect drift so let me go to my exchange server okay I'm looking at my exchange server now I'm going to stop that service manually where is it in this exchange transport okay so my transport service finally stopped all right so our services stops on exchange server now let's test the configuration so because V is C it came back as false so that exchange service is not running on my exchange server so there are a couple ways we can do this to start this and actually I need to put force on here I can use star DC configuration force this will rerun my configuration I'm not sure what that error message is let's see if it actually applied the configuration if it did restart the service all right so that's the basics of the DSC push model it's not dynamic at all it's there's a lot of manual testing and reapplying configuration if you detect drift but you can set this test DAC configuration command lit up to run at a certain period every day and notify an administrator if there is a problem the good thing with this is it takes nothing more than a client computer you can push it out to any machine provided it's running PowerShell v4 and above now you can do this a little more dynamically using the pull model which will probably be my next video and we'll go over that so appreciate you watching if you're not subscribed please consider subscribing if you have any questions hit me in the comments on Facebook Twitter whatever you wish and thank you again
Info
Channel: SignalWarrant
Views: 33,005
Rating: 4.9101124 out of 5
Keywords: powershell, desired state configuration manager, dsc, push model, local configuration manager, lcm, signalwarrant, signalwarrant.com, PowerShell v4, PowerShell v5, powershell for beginners, powershell script, powershell scripting for beginners, powershell tutorial, windows powershell
Id: o_a_IHDPo20
Channel Id: undefined
Length: 11min 45sec (705 seconds)
Published: Thu Jan 19 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.