ebook img

Windows PowerShell Desired State Configuration Revealed PDF

302 Pages·2014·11.57 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Windows PowerShell Desired State Configuration Revealed

BOOKS FOR PROFESSIONALS BY PROFESSIONALS® Chaganti Windows PowerShell Desired State RELATED Configuration Revealed Desired State Configuration (DSC) is a powerful new configuration management platform that makes it easier than ever to perform cross-platform configuration management of your infrastructure, whether on-premise or in the cloud. DSC provides the management platform and application programming interface (API) that can be used with any programming language. Windows PowerShell Desired State Configuration Revealed will take you through this new technology from start to finish and demonstrates the DSC interfaces through Windows PowerShell. DSC allows you to manage target devices by simply declaring what state you want them to be in, using new declarative language extensions, rather than writing detailed instructions to get them into that state. This makes continuous delivery in Windows easier than ever before. In an environment where changes and deployments are happening all the time, DSC makes the necessary adjustments to the system so you don’t have to. Windows PowerShell Desired State Configuration Revealed starts with an overview of the configuration management features in Windows, followed by a discussion of the architecture of DSC and its components. You’ll then explore DSC’s built-in features and resources, followed by some of the different methods provided for delivering configuration information within your ecosystem, and learn about configuration monitoring and reporting. In the latter part of the book, you’ll find out how to get more power out of DSC by writing your own custom DSC resources, including a range of useful examples. The book concludes with vital information on deploying and troubleshooting DSC in a production environment, along with some expert tips and tricks you might find useful along the way. Windows PowerShell Desired State Configuration Revealed is your one-stop guide to this new technology and how it can change your working life for the better. What you will learn: • Why continuous delivery and configuration management are important • Architecture and components of DSC • How to build the infrastructure required to automate configuration management • How to use built-in resources and create configuration documents • How to create custom DSC resources • How to troubleshoot DSC configuration and custom resource issues Shelve in ISBN 978-1-4842-0017-9 Windows/General 54999 User level: Beginning–Advanced SOURCE CODE ONLINE 9781484200179 www.apress.com www.it-ebooks.info For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. www.it-ebooks.info Contents at a Glance About the Author ����������������������������������������������������������������������������������������������������������������xv About the Technical Reviewer ������������������������������������������������������������������������������������������xvii Acknowledgments �������������������������������������������������������������������������������������������������������������xix Introduction �����������������������������������������������������������������������������������������������������������������������xxi ■ Part I: Introduction to Windows PowerShell �������������������������������������������������1 ■ Chapter 1: Beginning Windows PowerShell� ����������������������������������������������������������������������3 ■ Chapter 2: Introducing Windows Remote Management and CIM ������������������������������������43 ■ Part II: Desired State Configuration Essentials �������������������������������������������75 ■ Chapter 3: Introducing Desired State Configuration ��������������������������������������������������������77 ■ Chapter 4: Getting Started with DSC� �������������������������������������������������������������������������������91 ■ Chapter 5: Using Built-in DSC Resources ����������������������������������������������������������������������113 ■ Chapter 6: Building Advanced DSC Configurations �������������������������������������������������������151 ■ Part III: Advanced DSC Concepts and Tips ������������������������������������������������177 ■ Chapter 7: DSC Configuration Delivery Modes ���������������������������������������������������������������179 ■ Chapter 8: Monitoring, Correcting, and Reporting Configuration ����������������������������������207 ■ Chapter 9: Building Custom DSC Resources ������������������������������������������������������������������223 v www.it-ebooks.info ■ Contents at a GlanCe ■ Chapter 10: Troubleshooting Common DSC Issues ��������������������������������������������������������247 ■ Chapter 11: DSC—From the Field ����������������������������������������������������������������������������������257 ■ Appendix A: DSC Community Resources �����������������������������������������������������������������������269 ■ Appendix B: WMF 5�0 and DSC for Linux �����������������������������������������������������������������������277 Index ���������������������������������������������������������������������������������������������������������������������������������285 vi www.it-ebooks.info Introduction About the beginning of this year, Gwenan Spearing (at Apress) approached me to see if I was interested in writing a book on Desired State Configuration (DSC). I couldn’t say no, because after Windows PowerShell remoting and WMI/CIM, DSC has been my favorite subject. I have been writing and speaking about DSC since the first preview came out in 2013, and there is no better way to capture that experience than in a book such as this. Over last few years, IT service processes at various organizations, small and large, have been gearing up to support the Agile development and release cycles. It is no longer about how many features a product gains with every release cycle, but it is about how fast those features are delivered. As system administrators, developers, and DevOps engineers, you must have been experiencing this already. There are several tools and/or frameworks developed to support continuous delivery and configuration management in a data center. This is not a new subject, but it is certainly an area that is still evolving. There is no standard way of achieving your goals through these frameworks. Microsoft, with its Cloud OS vision, has been focusing on building tools that enable developers and IT professionals alike to build and manage cloud infrastructure. One such initiative is Desired State Configuration. DSC is a configuration standards-based management platform rather than a tool. DSC supports both Windows and Linux platforms. By management platform, we mean that the Application Programming Interfaces (API) provided by DSC can be used within any programming language, to manage configuration of devices and applications in a data center. This book provides an example of how these interfaces are used within PowerShell. While this book focuses on DSC with PowerShell, the concepts that you learn here can easily be leveraged in any programming or scripting language that has support for accessing DSC API. I have included several examples in each chapter, to build a greater understanding of the concepts. These examples do not require any special infrastructure. All that’s required is just a couple of virtual machines. An Overview of This Book Windows PowerShell Desired State Configuration Revealed is divided into three distinct parts. Each part contains related chapters that help you to understand thoroughly the concepts that are covered. Part I: Introduction to Windows PowerShell Part I provides an overview of Windows PowerShell as an automation engine and scripting language. It also includes a survey of Windows Remote Management (WinRM) and the Common Information Model (CIM). Chapter 1: Beginning Windows PowerShell This chapter introduces Windows PowerShell to beginners. The examples featured in this book require that you understand PowerShell, and it is necessary that you know the key PowerShell concepts, to make good use of the content of this book. For beginners, this chapter provides an overview that explains what PowerShell is, the need for PowerShell, the semantics of the PowerShell scripting language, and writing scripts, functions, and modules. Readers experienced with the key concepts of Windows PowerShell may choose to skip this chapter. xxi www.it-ebooks.info ■ IntroduCtIon Chapter 2: Introducing Windows Remote Management and CIM Desired State Configuration (DSC) is built on Windows Remote Management (WinRM) and Common Information Model (CIM). The most common DSC issues—discussed in Chapter 10—that you will face relate mostly to WinRM configuration or understanding CIM. This chapter builds a foundation for understanding these technologies. This knowledge is necessary to build the environment-use DSC for configuration management. Part II: Desired State Configuration Essentials This part of the book focuses on explaining DSC basics and general concepts. Using the knowledge you gain from Part I, you will learn in Part II how it can be applied to DSC. Chapter 3: Introducing Desired State Configuration Before delving into the DSC concepts, it is important that you understand the need for continuous delivery and configuration management and the challenges in employing these methodologies. Continuous delivery and configuration management are critical parts of almost every IT manager’s plan to ensure that data center service-level agreements are met. Microsoft invested in adding the infrastructure required to enable continuous configuration management and automation of the related tasks. This chapter describes how DSC fits the bill here and provides an introduction to configuring your environment for DSC. You will learn the difference between imperative and declarative syntax and how the declarative nature of DSC helps in simplifying configuration management tasks. Chapter 4: Getting Started with DSC Once you understand the need for configuration management and DSC itself, it is time to look at the basics of DSC. This chapter takes you through the architecture and components of DSC. While discussing the architecture, this chapter provides an overview of different phases in the DSC configuration management process and describes how each DSC component plays a role in one or more of these configuration management phases. Understanding these different phases in DSC configuration management, and how the components are used at each phase, is essential both for making DSC work for you and extending it as needed. By the end of this chapter, you will be able to create a DSC configuration script and apply the configuration, using DSC PowerShell cmdlets. Chapter 5: Using Built-in DSC Resources In any configuration management framework, an entity that is getting configured is called a configuration item. The management of these configuration items does not occur automatically. There has to be some code that understands how to configure the entity and perform it for you. This is implemented as resources in DSC. These resources are nothing but PowerShell modules or MI providers. DSC has a few built-in resource modules that help you configure such entities as Files and Folders, Registry, Windows features, Windows services, Windows processes, and so on. This chapter provides an overview of these built-in resources and demonstrates their use. Chapter 6: Building Advanced DSC Configurations In Chapters 4 and 5, you learn the basics of DSC configuration authoring and how to use built-in resources for writing configuration scripts. DSC offers patterns for making these configuration scripts reusable. This chapter explores parameterizing DSC configuration scripts, using configuration data, and creating nested configuration scripts. It also helps in understanding how credentials are used with DSC and what is needed to pass credentials as a part of configuration authoring. xxii www.it-ebooks.info ■ IntroduCtIon Part III: Advanced DSC Concepts and Tips While Part I and Part II of the book focus on the fundamentals of Windows PowerShell and Desired State Configuration, Part III builds on what you’ve learned to that point and describes the advanced concepts of DSC. Chapter 7: DSC Configuration Delivery Modes DSC supports two modes of configuration delivery: Push and Pull. Each of these modes has both advantages and disadvantages. This chapter provides in-depth information on how the configuration enactment process works in each of these delivery modes. You will learn how to use the Push mode of configuration delivery, its limitations, and the need for the Pull mode. You will learn how to configure DSC pull servers and clients and to deliver configuration and resource modules to the target systems. Chapter 8: Monitoring, Correcting, and Reporting Configuration Chapter 3 provides an overview of different phases in the configuration life cycle, describing that monitoring and correcting configuration drift is an essential step in configuration management. This chapter describes how DSC helps administrators in controlling configuration drift. To make complete use of these DSC features, it is essential that you understand what goes on behind the scenes when enacting configuration, using DSC. This chapter helps you gain this knowledge and provides examples on how to use DSC PowerShell cmdlets and Conformance server endpoint to monitor configuration. You will also see how the DSC Local Configuration Manager can be configured to detect and auto-correct configuration drift. Chapter 9: Building Custom DSC Resources Chapter 5 provides an overview of built-in DSC resources. These resources are either binary or script PowerShell modules or MI providers. This chapter provides in-depth information about authoring PowerShell script modules as custom DSC resources. This chapter provides an overview of the semantics and walks you through building a complete custom DSC resource for managing hosts file entries. In this chapter, you will also learn how to add help content for custom resources and how to localize messages from the custom DSC resources. Chapter 10: Troubleshooting Common DSC Issues In this chapter, you will discover some of the most common problems you may come across when using DSC and the solutions to them. This list of common issues was compiled based on my own experiences and from what I’ve learned helping others resolve issues in their own DSC deployment. The concepts and knowledge gained from earlier chapters is used here to understand and resolve a problem. There is no structured learning from this chapter, but it is a useful reference, should you encounter a problem using DSC. Chapter 11: DSC—From the Field This chapter provides an assorted collection of real-world scenarios, such as cross-domain configuration management with DSC, tips that make better use of DSC API, and best practices to follow when writing custom DSC resources and configuration scripts. The sections in this chapter are unrelated, and as in the case of Chapter 10, you can use this chapter as a reference for different topics that are covered in the book. xxiii www.it-ebooks.info ■ IntroduCtIon Appendix A: DSC Community Resources Chapter 9 provides an in-depth look into how custom DSC resources are created. While you can write PowerShell script modules as custom DSC resources for configuring almost anything you want, remember that there are also other people who are trying to solve the very same problem. To this extent, Microsoft has released several waves of a DSC resource kit that contains close to 50 custom DSC resources and helper utilities. This appendix provides an overview of some of the custom DSC resources that are a part of the resource kit and demonstrates how to use DSC resource designer, the DSC diagnostics module, and so on. Appendix B: WMF 5�0 and DSC for Linux This appendix explores some of the changes and enhancements to DSC on Windows through the WMF 5.0 preview release and looks at how to deploy and use DSC for Linux. These two components are still in the early stages of development, and the content in this chapter may or may not be applicable upon the final release. This is provided as an early guide, and I recommend that you consult any updated documentation from the preview releases, for more information. xxiv www.it-ebooks.info Part I Introduction to Windows PowerShell This part introduces you to Windows PowerShell and the foundational building blocks for Desired State Configuration (DSC). Chapter 1 takes you on a quick journey through PowerShell. We will look at the history of PowerShell, what the need for PowerShell is, and how PowerShell is different from the good old command shell and scripting languages of the past. You will learn how to explore PowerShell, using the cmdlets and interfaces provided by Windows PowerShell. You will also learn language semantics, such as data types, variables, operators, and flow control statements. Toward the end of Chapter 1, you will see how to create reusable PowerShell code, by writing functions, scripts, and modules. Chapter 2 takes you through the foundational building blocks of DSC—Windows Remote Management (WinRM) and Common Information Model (CIM). You will learn how WinRM is configured and used. After you gain a thorough understanding of WinRM, we will look at what CIM is and how your acquired knowledge of WinRM can be used with CIM cmdlets in Windows PowerShell. www.it-ebooks.info Chapter 1 Beginning Windows PowerShell For a Windows administrator, until early last decade, the options available for automation of administrative tasks were very limited. I started my career with the Windows NT platform and worked my way through limited scripting technologies, such as DOS batch scripts, VBScripts, JScripts, and so on. I had written several scripts to automate my daily tasks, and each of those scripts was tens to hundreds of lines in length. It was not easy and/or possible to integrate them with other automation technologies or scripting languages. For example, using VBScript, it was—and still is—impossible to access the functionality provided by .NET assemblies or Win32 native API. The Windows shell provided command-line tools to automate a few tasks, but the output generated by these tools is always text, which requires complex parsing, using regular expression techniques that generally intimidate any person getting started with scripting. While the technologies were great during that time, they had certain limitations, and compared to where we are today, they were not all that productive. One big reason for this was the lack of focus on command-line scripting within the Windows OS. Microsoft, to a large extent, focused on making an end user’s life easy, by providing excellent graphical user interfaces (GUIs). However, the lack of proper scripting tools and languages was certainly a shortcoming for the enterprise IT administrator. Microsoft realized this toward the beginning of the last decade and started investing in developing a better automation and scripting framework for the Windows OS. This was when Monad was born and later renamed to Windows PowerShell. The first version of PowerShell was released in 2006, and the most recent version, 4.0, in 2013. Every release added features to the scripting language and shell offered by PowerShell. Today, PowerShell is called an object-based command-line shell, distributed automation engine, and scripting language. True to its description, PowerShell is the most versatile and feature-rich automation platform on the market today, and it is endorsed by thousands of IT professionals and organizations worldwide. PowerShell is a critical part of Microsoft’s Common Engineering Criteria (CEC) and is adapted by many other partners and companies as the automation platform for their products. In this chapter, we look at some key concepts in Windows PowerShell that are important for any beginner. If you are already familiar with Windows PowerShell, you can skip to Chapter 2 and continue reading about Windows Management Instrumentation. However, if you are just getting started with PowerShell, this chapter offers an introduction to several concepts and provides examples to help you understand these concepts more clearly. What Is Windows PowerShell? This is the first question I get asked in a formal PowerShell training session for beginners or in an informal discussion with people who know virtually nothing about PowerShell. I like answering it by saying that PowerShell is an object- based command-line shell, distributed automation engine, and scripting language. Yes, I said that already! Let us start by looking at the specifics of this statement, to understand what PowerShell is. 3 www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.