{"id":53933,"date":"2009-04-20T15:14:00","date_gmt":"2009-04-20T15:14:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/04\/20\/hey-scripting-guy-windows-powershell-an-introduction\/"},"modified":"2009-04-20T15:14:00","modified_gmt":"2009-04-20T15:14:00","slug":"hey-scripting-guy-windows-powershell-an-introduction","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-windows-powershell-an-introduction\/","title":{"rendered":"Hey, Scripting Guy! Windows Powershell: An Introduction"},"content":{"rendered":"<h2><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" width=\"34\" height=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\"> Hey, Scripting Guy! Your Windows PowerShell articles have been real interesting, and I have been fascinated by the things you can do. But I need you to start at the beginning. It all looks real confusing to me. How about it? <\/p>\n<p>&#8211; TD<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" width=\"5\" height=\"5\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" width=\"34\" height=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\"><\/p>\n<p>Hi TD,<\/p>\n<p>You know things are only confusing when you do not understand them. We remember very well the first time we downloaded and installed Windows PowerShell. We also remember a painful couple of weeks spent with our heads down over the computer console trying to figure things out back when there were no books written on the subject and the product was still in beta, and even the Help files were incomplete. Ed remembers very well his first thought after installing Windows PowerShell: &#8220;Dude, this is different.&#8221; <\/p>\n<table id=\"EXC\" class=\"dataTable\" cellspacing=\"0\" cellpadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">This week we will be looking at the basics of Windows PowerShell. Windows PowerShell is installed by default on Windows 7 and Windows Server 2008 R2. It is an optional installation on Windows Server 2008 and a download for <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?displaylang=en&amp;FamilyID=c6ef4735-c7de-46a2-997a-ea58fdfcba63\">Windows Vista<\/a>, <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?displaylang=en&amp;FamilyID=6ccb7e0d-8f1d-4b97-a397-47bcc8ba3806\">Windows XP<\/a>, and <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?displaylang=en&amp;FamilyID=10ee29af-7c3a-4057-8367-c9c1dab6e2bf\">Windows Server 2003<\/a>. The <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">Windows PowerShell Scripting Hub<\/a> is a good place to get started with Windows PowerShell.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>So what is Windows PowerShell? For people who come from a Windows background, Windows PowerShell will take some getting used to because it provides a new kind of capability to the environment. On the one hand, there is the Windows PowerShell console that enables you to type commands in an interactive manner. On the other hand, it is a scripting language that lets you write scripts. It is similar to taking the command prompt and putting VBScript inside it. You get two tools in one. It is like a chocolate bar with almonds in it: You get both chocolate and nuts.<\/p>\n<p>The heart of Windows PowerShell is the cmdlets that are included with the product. These cmdlets are built into Windows PowerShell, but can also be written by other people to provide additional capability. Let&#8217;s open Windows PowerShell, and get information about all the processes running on our computer. The <b>Get-Process<\/b> cmdlet returns information about the process ID, how much CPU time is being consumed, and memory consumption. The cmdlet is <b>Get-Process<\/b>, and the results are seen here:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of detailed process information provided by the Get-Process cmdlet\" width=\"500\" height=\"409\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0420\/hsg-04-20-09-01.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>If we are interested in services, the Windows PowerShell cmdlet is <b>Get-Service<\/b>. When we run this cmdlet, we get information about the service name, status, and display name. The results are shown here:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of the information provided by the Get-Service cmdlet\" width=\"500\" height=\"409\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0420\/hsg-04-20-09-02.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>If we want to get the date, the cmdlet is <b>Get-Date<\/b>, and if we want the culture settings on the computer, we use <b>Get-Culture<\/b>. But we are not limited to just using Windows PowerShell cmdlets within the Windows PowerShell console. We can also use external commands such as <b>getmac.exe<\/b>. This is shown here:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of both Windows PowerShell cmdlets and external commands being combined in the same Windows PowerShell session\" width=\"500\" height=\"203\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0420\/hsg-04-20-09-03.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>To this point, all of our cmdlets have begun with the word <b>Get<\/b> and have been followed by another word. All Windows PowerShell cmdlet names are made up of two parts. The first part of the cmdlet name is called a verb, and the second part of the cmdlet name is called a noun. These are not strictly grammatical in definition. But the idea can be summarized as follows: &#8220;What do you want to do, and what do you want to do it to?&#8221; A standard set of verbs makes it easy to remember the cmdlet name. As an example, a common task by network administrators is to stop a process. Many different utilities require us to remember to stop, unload, delete, kill, terminate, or some other permutation of ending a process. In Windows PowerShell it is easy&mdash;the verb is always <b>S<\/b><b>top<\/b>. If you want to start something; you use the <b>Start<\/b> verb. A listing of the verbs from Windows PowerShell 1.0 is seen in <b>Table 1<\/b>.<\/p>\n<table id=\"EFF\" class=\"dataTable\" cellspacing=\"0\" cellpadding=\"0\">\n<thead>\n<tr>\n<td class=\"tableHeader\" colspan=\"2\">Table 1 Windows PowerShell 1.0 verbs<\/td>\n<\/tr>\n<tr class=\"stdHeader\" valign=\"top\">\n<td id=\"colEIF\">Name<\/td>\n<td id=\"colEMF\">Count<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Add<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Clear<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Compare<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">ConvertFrom<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Convert<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">ConvertTo<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Copy<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Export<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">ForEach<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Format<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Get<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">29<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Group<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Import<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Invoke<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Join<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Measure<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Move<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">New<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Out<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">6<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Pop<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Push<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Read<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Remove<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">5<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Rename<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Resolve<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Restart<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Resume<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Select<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Set<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">13<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Sort<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Split<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Start<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Stop<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">3<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Suspend<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Tee<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Test<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Trace<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Update<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Where<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\">Write<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">7<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>You can also use Windows PowerShell in ways that are already familiar to you. For example, if you want to get a directory listing, you can type <b>d<\/b><b>ir<\/b> as shown here:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of using dir to get a directory listing\" width=\"500\" height=\"311\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0420\/hsg-04-20-09-04.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>To create a directory, you can use the <b>md<\/b> command and tell it the name of the directory you want to create. As soon as a directory is created, you can create a text file by using the redirection arrows to capture the results of a command such as the <b>dir<\/b> command that was used earlier. This is shown here:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of the command to create a text file\" width=\"500\" height=\"176\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0420\/hsg-04-20-09-05.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>The text file that was created in the previous command is shown here:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of the text file created by the previous command\" width=\"500\" height=\"343\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0420\/hsg-04-20-09-06.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>The last thing you might want to do is delete a text file and a folder. To do this, you use the <b>del<\/b> command to delete a file. The first thing that you might want to do is to change your working directory to the <b>c:hsgTest<\/b> folder that was created earlier. To do this, you use a command that is familiar to you: the <b>cd<\/b> command. As soon as you are in the directory, you may want to get another directory listing by using the <b>dir<\/b> command. Next, you use the <b>del<\/b> command to delete the <b>directory.txt<\/b> file. As shown in the following image, the file name is preceded by a <b>&#8220;.&#8221;<\/b> character. This means that you are interested in the file in the current directory. When you type the first couple of letters of the file name and press the tab key, the <b>&#8220;.&#8221;<\/b> is automatically added to the file name in addition to expanding to the complete file name. This enables you to avoid typing the complete file name. The feature is known as tab expansion.<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Image of deleting a file\" width=\"500\" height=\"203\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0420\/hsg-04-20-09-07.jpg\"><\/p>\n<p>&nbsp;<\/p>\n<p>Well, TD, as you can see, working with Windows PowerShell can be as easy as working at the command prompt. We hope that you have enjoyed this introduction. Join us tomorrow as Windows PowerShell Basics Week continues. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Your Windows PowerShell articles have been real interesting, and I have been fascinated by the things you can do. But I need you to start at the beginning. It all looks real confusing to me. How about it? &#8211; TD Hi TD, You know things are only confusing when you do not [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,3,4,45],"class_list":["post-53933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Your Windows PowerShell articles have been real interesting, and I have been fascinated by the things you can do. But I need you to start at the beginning. It all looks real confusing to me. How about it? &#8211; TD Hi TD, You know things are only confusing when you do not [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53933","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=53933"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53933\/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=53933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=53933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=53933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}