{"id":13521,"date":"2011-06-25T00:01:00","date_gmt":"2011-06-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/06\/25\/dont-write-powershell-scripts\/"},"modified":"2011-06-25T00:01:00","modified_gmt":"2011-06-25T00:01:00","slug":"dont-write-powershell-scripts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/dont-write-powershell-scripts\/","title":{"rendered":"Don&#8217;t Write PowerShell Scripts"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy Ed Wilson talks about when to not write a Windows PowerShell script.<\/p>\n<h2><strong>Weekend Scripter<\/strong><\/h2>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Network administrators do not script! ITPros do not like to script! I have heard statements like this for years. Yet, when I first wrote my VBScript workshop for Microsoft Premier Workshops, it quickly became the most popular of all workshop offerings. So what gives? Is there a disconnect? Do ITPros really like to write scripts? Is there a secret developer hiding inside net admins that is struggling to make itself known? I do not think so. Rather, I believe that the desire to &ldquo;learn&rdquo; scripting is the desire to ease network administration duties. I believe the impetus to acquire scripting skills is the wish to automate repetitive tasks. In the past, these twin needs and goals did require learning rudimentary (and at times more advanced) programming skills, but this is no longer the case. <\/p>\n<p>Microsoft Windows PowerShell MVP, Don Jones, caused a minor tempest in the Windows PowerShell community when he declared that Windows PowerShell was not a &ldquo;scripting language.&rdquo; To an extent he was kidding<b><i>,<\/i><\/b><i> <\/i>but he also had a point because Windows PowerShell is an automation tool. <\/p>\n<p>I believe, within reason, that the days of writing scripts are rapidly drawing to a close. To the extent that customization is required, it can be handled in the pipeline. To the extent that new functionality is required, it is best handled as an advanced function. <\/p>\n<p>I think a couple of examples are in order to illustrate what I am talking about. Consider the simple case of checking the version of the BIOS on the computer. In the old-fashioned VBScript days, a script such as the following was the order of the day. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">GetBiosInformation.vbs<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">On Error Resume Next<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">strComputer = &#8220;.&#8221;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_BIOS&#8221;,,48)<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">For Each objItem in colItems<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;BiosCharacteristics: &#8221; &amp; objItem.BiosCharacteristics<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;BIOSVersion: &#8221; &amp; objItem.BIOSVersion<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;BuildNumber: &#8221; &amp; objItem.BuildNumber<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;Caption: &#8221; &amp; objItem.Caption<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;CodeSet: &#8221; &amp; objItem.CodeSet<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;CurrentLanguage: &#8221; &amp; objItem.CurrentLanguage<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;Description: &#8221; &amp; objItem.Description<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;IdentificationCode: &#8221; &amp; objItem.IdentificationCode<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;InstallableLanguages: &#8221; &amp; objItem.InstallableLanguages<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;InstallDate: &#8221; &amp; objItem.InstallDate<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;LanguageEdition: &#8221; &amp; objItem.LanguageEdition<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;ListOfLanguages: &#8221; &amp; objItem.ListOfLanguages<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;Manufacturer: &#8221; &amp; objItem.Manufacturer<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;Name: &#8221; &amp; objItem.Name<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;OtherTargetOS: &#8221; &amp; objItem.OtherTargetOS<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;PrimaryBIOS: &#8221; &amp; objItem.PrimaryBIOS<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;ReleaseDate: &#8221; &amp; objItem.ReleaseDate<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;SerialNumber: &#8221; &amp; objItem.SerialNumber<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;SMBIOSBIOSVersion: &#8221; &amp; objItem.SMBIOSBIOSVersion<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;SMBIOSMajorVersion: &#8221; &amp; objItem.SMBIOSMajorVersion<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;SMBIOSMinorVersion: &#8221; &amp; objItem.SMBIOSMinorVersion<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;SMBIOSPresent: &#8221; &amp; objItem.SMBIOSPresent<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;SoftwareElementID: &#8221; &amp; objItem.SoftwareElementID<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;SoftwareElementState: &#8221; &amp; objItem.SoftwareElementState<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;Status: &#8221; &amp; objItem.Status<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;TargetOperatingSystem: &#8221; &amp; objItem.TargetOperatingSystem<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Wscript.Echo &#8220;Version: &#8221; &amp; objItem.Version<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Next<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>With Windows PowerShell, it is possible to replace that exact script with the following command. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-WmiObject Win32_bios | Format-List *<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The output from the VBScript script and the PowerShell command are nearly identical. <\/p>\n<p>Now, suppose I decide that I need to run the command to get BIOS information from a large number of computers. The choice of where the computer names reside is a different discussion, but for now suppose the computer names are stored in a text file, one computer name per line. To solve this scenario, I can use the command that is shown here. <\/p>\n<blockquote>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-WmiObject win32_bios -cn (Get-Content C:\\fso\\Servers.txt)<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If I need to use different credentials (an account other than the one that I am currently using) to run the command, I use the <i>Credential<\/i> parameter as shown here. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-WmiObject win32_bios -cn (Get-Content C:\\fso\\Servers.txt) &ndash;credential nwtraders\\administrator<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>When the command runs, a dialog box appears that prompts me to enter my password. This password is encrypted as it is transmitted because it is retrieved and handled as a secure string. The dialog box for the password is shown in the following image. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7737.Credential_5AFBA53D.jpg\"><img decoding=\"async\" height=\"334\" width=\"404\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1464.Credential_thumb_2CA21F90.jpg\" alt=\"Image of text box\" border=\"0\" title=\"Image of text box\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>Well, this is all fine and dandy, but to be honest, it is a bit silly to read a text file that contains dozens (or even hundreds) of computer names, and then display the results to the console. It makes more sense to output the information somewhere. I like writing the data to a database and using the SQLPSX modules. It is really trivial to write information to a database. The easiest way to store the returned information is to use redirection arrows and write the returned data to a text file. This technique is shown here. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-WmiObject win32_bios -cn (Get-Content C:\\fso\\Servers.txt) &gt;&gt; c:\\fso\\biosInfo.txt<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Because I am working interactively in the Windows PowerShell console, I might want to shorten the syntax a bit by using commonly available aliases for the commands. To do this, the previous command becomes:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">gwmi win32_bios -cn (cat C:\\fso\\Servers.txt) &gt;&gt; c:\\fso\\biosInfo.txt<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>This command works because <b>gwmi<\/b> is an alias for the <b>Get-WmiObject<\/b> cmdlet. I need to let the <b>Get-WmiObject <\/b>cmdlet know what I intend to do with the results of my <b>Get-Content<\/b> cmdlet. I can use <b>cn<\/b> as an alias for the longer C<i>omputerName <\/i>parameter (in fact, I have cheated all along on this detail today). There are three default aliases for the <b>Get-Content<\/b> cmdlet. I found them by using the <b>Get-Aliases<\/b> cmdlet as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">PS C:\\&gt; Get-Alias -Definition get-content<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">CommandType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Definition<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>cat<span>&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-Content<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>gc<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-Content<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>type<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-Content<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If you do not like any of the default aliases, you can create your own alias. For example, if you like dogs better than cats, you can create a new alias as shown here. One thing to keep in mind, is that nothing is returned when you create a new alias in this manner. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">PS C:\\&gt; New-Alias -Name dog -Value get-content<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">PS C:\\&gt;<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>You can always check to ensure that the new alias &ldquo;took&rdquo; by using the <b>Get-Alias<\/b> cmdlet as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">PS C:\\&gt; Get-Alias dog<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">CommandType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Definition<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>dog<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>get-content<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Or better yet, you can simply try the new command and see what happens. This is what I do here. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">gwmi win32_bios -cn (dog C:\\fso\\Servers.txt)<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>None of this required any scripting. Now suppose in my testing, I detect that there is a bad BIOS version. I mean, it is the sort of thing that causes my servers to emit a BSOD (blue screen of death). In the past, I would need to write a script to check for that. But by using Windows PowerShell, I simply &ldquo;tack&rdquo; an additional cmdlet to the end of my pipeline. The revised command is shown here. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-WmiObject win32_bios -cn (Get-Content C:\\fso\\Servers.txt) | <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Where-Object { $_.version -match &#8216;2170&#8217;}<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Note: The previous command is a single logical command. I broke it at the pipeline character (|) so it would fit better in the blog format. <\/p>\n<p>I can shorten this command by using aliases. In the short version, <b>gwmi<\/b> is an alias for the <b>Get-WmiObject<\/b> cmdlet. I use <b>gc<\/b> for <b>Get-Content<\/b>, and the question mark (<b>?<\/b>) as an alias for the <b>Where-Object<\/b> cmdlet. The short version of this command is shown here. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">gwmi win32_bios -cn (gc C:\\fso\\Servers.txt) | ? { $_.version -match &#8216;2170&#8217;}<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If I only need a list of the servers that will need the BIOS update, I add an additional cmdlet to the end of the command. This time, I use the <b>Select-Object<\/b> cmdlet to retrieve the <b>__Server<\/b> property (that is a double underscore character at the beginning of the <b>__Server<\/b> property). In WMI, there is always a system property named <b>__Server<\/b> that stores the name of the computer. This property exists in nearly every WMI class. The revised command is shown here. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-WmiObject win32_bios -cn (Get-Content C:\\fso\\Servers.txt) | <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Where-Object { $_.version -match &#8216;2170&#8217;} | Select-Object __Server <\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Once again, this is a single logical command. I broke the command at the pipeline character (|) to better format the command for the blog. <\/p>\n<p>I can shorten this command by using aliases. There is a default alias of <b>Select<\/b><i> <\/i>for the <b>Select-Object<\/b> cmdlet. A short version of the command is shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">gwmi win32_bios -cn (gc C:\\fso\\Servers.txt) | ? { $_.version -match &#8216;2170&#8217;} | select __Server<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Even by using aliases, the command is becoming a bit long. But the cool thing is that the command is built incrementally, and I can use the command buffer to retrieve and to edit my commands. <\/p>\n<p>I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy Ed Wilson talks about when to not write a Windows PowerShell script. Weekend Scripter Microsoft Scripting Guy, Ed Wilson, is here. Network administrators do not script! ITPros do not like to script! I have heard statements like this for years. Yet, when I first wrote my VBScript workshop for Microsoft Premier [&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":[3,4,45,77],"class_list":["post-13521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-writing"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy Ed Wilson talks about when to not write a Windows PowerShell script. Weekend Scripter Microsoft Scripting Guy, Ed Wilson, is here. Network administrators do not script! ITPros do not like to script! I have heard statements like this for years. Yet, when I first wrote my VBScript workshop for Microsoft Premier [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13521","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=13521"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13521\/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=13521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}