{"id":144711,"date":"2018-11-30T19:39:00","date_gmt":"2018-11-30T19:39:00","guid":{"rendered":"https:\/\/ccbtechnology.com\/?p=144711"},"modified":"2024-05-06T08:27:02","modified_gmt":"2024-05-06T08:27:02","slug":"powershell-cmdlets-built-in-hidden-secrets","status":"publish","type":"post","link":"https:\/\/ccbtechnology.com\/powershell-cmdlets-built-in-hidden-secrets\/","title":{"rendered":"PowerShell Documentation Cmdlets &#8211; The Built-in Hidden Secrets"},"content":{"rendered":"<p>From automating simple but time-consuming tasks, to carrying out advanced functions in Microsoft 365 that aren\u2019t available in the graphical interface, PowerShell has near limitless potential. Having a better understanding of how PowerShell works opens up a number of possibilities for how it can be used. In this blog, we will investigate some of the useful documentation features built directly into PowerShell and how they can assist in better understanding the cmdlets and objects that you are working with.<\/p>\n<p>If you\u2019re just <a href=\"https:\/\/ccbtechnology.com\/what-is-powershell\/\" target=\"_blank\" rel=\"noopener\">getting started with PowerShell<\/a>, first start with the basics \u2013 what it is, what it\u2019s used for, and why it\u2019s a formidable tool for administrators in today\u2019s IT landscape.<\/p>\n<h2>Using Cmdlets<\/h2>\n<p>Cmdlets make up the core of how PowerShell is used. If you are not familiar with what they are, head over to our <a href=\"https:\/\/ccbtechnology.com\/what-is-powershell\/\" target=\"_blank\" rel=\"noopener noreferrer\">PowerShell Primer article<\/a> to take a look. One commonly demonstrated Cmdlet is Get-Process. The Get-Process command gets the processes on a local or remote computer. Without parameters, this cmdlet gets all of the processes on the local computer. You can also specify a particular process by process name or process ID (PID) or pass a process object through the pipeline to this cmdlet.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-144718 size-full\" src=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/get-process.png\" alt=\"\" width=\"859\" height=\"418\" srcset=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/get-process.png 859w, https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/get-process-300x146.png 300w, https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/get-process-768x374.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/p>\n<p>PowerShell has an impressive way of helping users work more productively as well as assisting in remembering the larger number of Cmdlets contained within the system \u2013 Tab Complete. From a PowerShell console, simply start typing the command. After a few characters, you can press the tab key to have PowerShell complete the Cmdlet for you.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-144720 size-full\" src=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/get-process-Tab-complete.gif\" alt=\"\" width=\"502\" height=\"203\" \/><\/p>\n<p>Tab complete is a lifesaver when it comes to working with PowerShell, especially when what has been typed into the console is ambiguous and the options need to be cycled through. You can either continue pressing tab to move through the list or in newer versions of PowerShell, you can press Ctrl + Space to bring up a full list of available commands.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-144719 size-full\" src=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/ctrl-space.gif\" alt=\"\" width=\"853\" height=\"203\" \/><\/p>\n<h2><strong>Two of my favorite Cmdlets<\/strong><\/h2>\n<p>Combining one\u2019s knowledge with what\u2019s available using PowerShell\u2019s built-in documentation can prove to be a powerful asset. Two of my favorite Cmdlets are Get-Help and Get-Member. In this next section, I\u2019ll break down what these Cmdlets do and how I use them to support my workflow.<\/p>\n<h3><strong>Get-Help<\/strong><\/h3>\n<p>The description for what the Get-Process cmdlet does was mentioned above. That information can be attained <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/Microsoft.PowerShell.Management\/Get-Process?view=powershell-5.0\" target=\"_blank\" rel=\"noopener\">online<\/a> or directly from the PowerShell console. Having the information directly available is one of the significant advantages of PowerShell compared to other scripting languages. Information about the cmdlets, the correct syntax, list of parameters, and even examples can all be reached without leaving the console or having to involve an outside resource. There are, of course, lots of great resources online with detailed examples and explanations \u2013 but those aren\u2019t always readily available or accessible on a machine that may not have an internet connection or even more constraining, a machine with no graphical user interface (GUI).<\/p>\n<p>Here is the example of what it looks like to the help documentation for the Get-Process cmdlet:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-144721 size-full\" src=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gh-gp.gif\" alt=\"\" width=\"859\" height=\"732\" \/><\/p>\n<p>Note the first time you run Get-Help, you may be prompted to download updated help files. This requires an active internet connection and will take some time. This process pulls the latest help information down locally to your machine. If you are not able to run the update you can still view the help information \u2013 it just may not be the latest version. In many cases, this can still help you work through running the command, but it may not have any updated documentation.<\/p>\n<p>Let\u2019s break down this output.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-144722 size-full\" src=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gh-gpfull.png\" alt=\"\" width=\"859\" height=\"732\" srcset=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gh-gpfull.png 859w, https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gh-gpfull-300x256.png 300w, https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gh-gpfull-768x654.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/p>\n<p>The first two sections provide the name of the cmdlet and a synopsis of what the command does. A detailed description can be found just below the syntax. The syntax section explains how the cmdlet can be run. It shows the parameters that can be passed to the cmdlet, what type of objects they need to be, and whether or not a parameter is required. You can find more information on PowerShell syntax <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.core\/about\/about_command_syntax?view=powershell-6\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> and <a href=\"https:\/\/ss64.com\/ps\/syntax.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p>In the remarks section, there are a few additional parameters you can pass to the Get-Help Get-Process command to view more information. Most notable is the -examples switch parameter. This provides a list of examples for how the command works. A few things for you to try out:<br \/>\nGet-Help Get-Process -examples<br \/>\nGet-Help Get-Process -detailed<\/p>\n<p>This provides you with a more detailed version of the information shown above.<\/p>\n<p>And you can even run Get-Help against itself to view all the ways that you can discover information about how PowerShell works. So, if you\u2019re in the mood for some \u201clight lunchtime reading\u201d check out Get-Help Get-Help -full for some riveting information (ok maybe that\u2019s just an engineer thing).<\/p>\n<h3><strong>Get-Member<\/strong><\/h3>\n<p>Get-Member is one of the other commands that I often use when working in PowerShell. PowerShell is an object-orientated language. This means that we can reference different parts or attributes of an object as we are working in the console or with a script. An object also contains different methods (or functions) that it can perform. The Get-Member command provides a view of what the object looks like. Try it yourself with the Get-Process command:<\/p>\n<p>Get-Process | Get-Member<\/p>\n<p>For those that aren\u2019t aware, the vertical bar character in the middle is called a pipe. It\u2019s located above the enter key.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-144723 size-full\" src=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gp-gm.png\" alt=\"\" width=\"734\" height=\"364\" srcset=\"https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gp-gm.png 734w, https:\/\/ccbtechnology.com\/wp-content\/uploads\/2018\/11\/gp-gm-300x149.png 300w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/p>\n<p>When you are running Get-Member, you are looking at the members (or properties) of an object. In the example above, you are looking at the parts of the Process object (System.Diagnostics.Process). The output of the above command allows you to see what you can do with the process object, how you can interact with it, and other attributes. Some of the methods worth mentioning are start (which will start a system process) and close (which does the same thing as its name implies). The complete output is a bit long to include here, but feel free to run the above command and see for yourself.<\/p>\n<p>By using a combination of Get-Help and Get-Member, you can get a better understanding of how cmdlets interact with each other and objects. In a future article, we\u2019ll investigate starting to harness the capabilities of PowerShell and how it can help save you time and effort when it comes to managing an environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From automating simple but time-consuming tasks, to carrying out advanced functions in Microsoft 365 that aren\u2019t available in the graphical interface, PowerShell has near limitless [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":160955,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[4],"tags":[],"class_list":["post-144711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft"],"acf":[],"_links":{"self":[{"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/posts\/144711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/comments?post=144711"}],"version-history":[{"count":0,"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/posts\/144711\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/media\/160955"}],"wp:attachment":[{"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/media?parent=144711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/categories?post=144711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ccbtechnology.com\/wp-json\/wp\/v2\/tags?post=144711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}