{"id":1925,"date":"2014-02-26T00:01:00","date_gmt":"2014-02-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/02\/26\/apply-common-powershell-concepts-to-configuration-manager\/"},"modified":"2014-02-26T00:01:00","modified_gmt":"2014-02-26T00:01:00","slug":"apply-common-powershell-concepts-to-configuration-manager","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/apply-common-powershell-concepts-to-configuration-manager\/","title":{"rendered":"Apply Common PowerShell Concepts to Configuration Manager"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft PFE, Heath Lawson, talks about applying common Windows PowerShell concepts to Configuration Manager.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today we welcome guest blogger, Heath Lawson. Heath is a System Center premier field engineer based in Kansas City, Missouri. He often posts about System Center-related scripting and automation in his blog, <a href=\"http:\/\/blogs.msdn.com\/b\/helaw\/\" target=\"_blank\">HeLaw&#039;s Blog: System Center&#8230;Tying it all together!<\/a><\/p>\n<p>Heath Lawson here, checking in for the first of three posts. My background is heavy in Configuration Manager, although I love all aspects of automation and scripting, so the opportunity to write guest posts here is amazing! This series is intended to help Configuration Manager folks jump into scripting and automation by helping them gain an understanding of how common Windows PowerShell concepts can&nbsp;apply to Configuration Manager.<\/p>\n<p>There are three posts to this series, the first will cover&nbsp;how to interact with&nbsp;the&nbsp;Windows PowerShell&nbsp;support starting with Configuration Manager&nbsp;2012 Service Pack 1, the second is an&nbsp;advanced look at using cmdlets to get work done, and the third is about taking care of business without using the native Windows PowerShell cmdlets.&nbsp;These&nbsp;posts will assume that you have a very basic understanding of Windows PowerShell; and if you don&rsquo;t,&nbsp;you&rsquo;re in the right spot because the Scripting Guys have some fantastic resources&nbsp;here to get you up to speed.<\/p>\n<p>System Center Configuration Manager&nbsp;2012 introduced Windows PowerShell support starting with Service Pack 1. Each cumulative update typically finds new or updated Windows PowerShell functionality, although the differences can be subtle. The most current version is System Center&nbsp;2012&nbsp;R2, so all of the examples here will be shown with the System Center&nbsp;2012&nbsp;R2 versions of the cmdlets. Understand that there may be differences if you&rsquo;re not using System Center&nbsp;2012&nbsp;R2.<\/p>\n<p>The goal of this post is to take a common action, and then create a new collection and set a few properties&hellip;all with Windows PowerShell. I like to show and tell when it comes to scripting, so we&rsquo;ll jump into the lab and get started. We can easily do that that within the Configuration Manager console by clicking the upper-left corner and launching the Windows PowerShell session.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-1.png\"><img decoding=\"async\" title=\"Image of menu\" alt=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-1.png\" \/><\/a><\/p>\n<p>After we click the menu item that is highlighted, we&rsquo;ll be presented with a Windows PowerShell session with the Configuration Manager module loaded:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-2.png\"><img decoding=\"async\" title=\"Image of screen\" alt=\"Image of screen\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-2.png\" \/><\/a><\/p>\n<h2>What is P35?<\/h2>\n<p>Now, we have our Windows PowerShell session, but why is it referencing P35? Well, for the astute readers out there, you&rsquo;ll notice in the top screenshot, that is my site code for Configuration Manager. The reason for this is that the Configuration Manager module registers itself as a Windows PowerShell provider and creates a Windows PowerShell drive.<\/p>\n<h2>It&rsquo;s just a Windows PowerShell drive<\/h2>\n<p>A little background on the Configuration Manager PowerShell module&hellip;<\/p>\n<p>First, all of the&nbsp;Windows PowerShell functionality in Configuration Manager is contained within the&nbsp;ConfigurationManager.psd1<i> <\/i>module, which is located in the &lt;Install Path&gt;\\AdminConsole\\Bin\\i386 directory. Additionally, the module references the site code of where the console has connected. This is important to understand for automation scenarios because we have to fire up the console as the user running Windows PowerShell at least once to make sure we reference our site code via the provider.<\/p>\n<p>Now that we have our Windows PowerShell session loaded and we understand that our functionality is going to come from the Configuration Manager module, let&rsquo;s&nbsp;get started creating our collection. First, we need to understand which cmdlet to run to create a new collection. To find that, we&rsquo;ll&nbsp;run a quick&nbsp;command to find all of the commands in our Configuration Manager module that have a name that contains <b>Collection<\/b>:<\/p>\n<p style=\"margin-left:30px\">Get-Command -Module ConfigurationManager |&nbsp;Where-Object {$_.Name -like &#039;*Collection*&#039;}<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-3.png\"><img decoding=\"async\" title=\"Image of command output\" alt=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-3.png\" \/><\/a><\/p>\n<h2>A new Configuration Manager collection<\/h2>\n<p>Well, this seems great. In true Windows PowerShell verb-noun form, we can see that there is a <b>New-CMDeviceCollection<\/b> cmdlet available! Also, from this view, you&rsquo;ll notice all of the Configuration Manager cmdlets are easily identifiable because the noun portion of the cmdlets is prefixed with <b>CM<\/b>.<\/p>\n<p>One of the great things about Windows PowerShell is that it contains plenty of built-in documentation, and that documentation updates on a regular basis. One point here, the Configuration Manager module ships with older documentation. You can issue the <b>Update-Help<\/b> cmdlet to update your Configuration Manager documentation. With that out of the way, let&rsquo;s get more information on the <b>New-CMDeviceCollection <\/b>cmdlet and see what we need to do to use it to create a collection for us.<\/p>\n<p style=\"margin-left:30px\">Get-Help New-CMDeviceCollection<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-4.png\"><img decoding=\"async\" title=\"Image of command output\" alt=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-4.png\" \/><\/a><\/p>\n<p>As we can see in this image, <b>New-CMDeviceCollection<\/b> gives us a few options, such as name and refresh type. Collections in Configuration Manager&nbsp;2012 must be limited to another collection, so we know we&rsquo;re going to have to specify the limiting collection and a collection name. As we can see in this image, it calls that out for us.<\/p>\n<p>Optionally, for those who feel like experimenting, we can use the Tab key to auto-complete for us in Windows PowerShell. One of my common short cuts is to simply type the cmdlet and then &ldquo;<b>&#8211;<\/b>&ldquo;. From there, press the Tab key and you&rsquo;ll see it auto-complete the parameters that are available for the cmdlet. Cool, huh?<\/p>\n<p>Anyway, back to it&hellip;<\/p>\n<p>Let&rsquo;s create a new collection! We&rsquo;re going to stack together the previous information and put together a single line of Windows PowerShell that will create a collection:<\/p>\n<p style=\"margin-left:30px\">New-CMDeviceCollection&nbsp;&ndash;Name &ldquo;All Windows&nbsp;Server&nbsp;2012&nbsp;R2&nbsp;Devices&rdquo;&nbsp;&ndash;LimitingCollectionName &ldquo;All Systems&rdquo;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-5.png\"><img decoding=\"async\" title=\"Image of command output\" alt=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-26-14-5.png\" \/><\/a><\/p>\n<p>With that, we have a Configuration Manager collection!<\/p>\n<p>In this section, we learned how to look at the cmdlets that are available within the Configuration Manager module and how to get additional Help about a cmdlet, and we were able to create a collection using nothing but one line of Windows PowerShell. There are 560 Windows PowerShell cmdlets available with Configuration Manager&nbsp;2012&nbsp;R2, so I encourage you to get to know them and understand how they can make administration simpler.<\/p>\n<p>~Heath<\/p>\n<p>Thank you, Heath, for writing this series and sharing. I am looking forward to Part&nbsp;2.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft PFE, Heath Lawson, talks about applying common Windows PowerShell concepts to Configuration Manager. Microsoft Scripting Guy, Ed Wilson, is here. Today we welcome guest blogger, Heath Lawson. Heath is a System Center premier field engineer based in Kansas City, Missouri. He often posts about System Center-related scripting and automation in his blog, HeLaw&#039;s [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[487,56,488,3,489,45],"class_list":["post-1925","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-configuration-manager","tag-guest-blogger","tag-heath-lawson","tag-scripting-guy","tag-system-center","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft PFE, Heath Lawson, talks about applying common Windows PowerShell concepts to Configuration Manager. Microsoft Scripting Guy, Ed Wilson, is here. Today we welcome guest blogger, Heath Lawson. Heath is a System Center premier field engineer based in Kansas City, Missouri. He often posts about System Center-related scripting and automation in his blog, HeLaw&#039;s [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1925"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1925\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}