{"id":51513,"date":"2010-01-21T00:01:00","date_gmt":"2010-01-21T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/01\/21\/hey-scripting-guy-can-you-give-all-the-steps-for-creating-installing-and-using-windows-powershell-modules\/"},"modified":"2010-01-21T00:01:00","modified_gmt":"2010-01-21T00:01:00","slug":"hey-scripting-guy-can-you-give-all-the-steps-for-creating-installing-and-using-windows-powershell-modules","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-can-you-give-all-the-steps-for-creating-installing-and-using-windows-powershell-modules\/","title":{"rendered":"Hey, Scripting Guy! Can You Give All the Steps for Creating, Installing, and Using Windows PowerShell Modules?"},"content":{"rendered":"<p><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a><\/p>\n<p>&nbsp;\n<font size=\"2\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/font><\/p>\n<p class=\"MsoNormal\">Hey, Scripting Guy! I am still a bit confused about how modules work. Could you give a beginning-to-end scenario and go through the steps of creating a module, installing the module, and then using the module?<\/p>\n<p class=\"MsoNormal\">&#8212; SL<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello, SL. <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. I am sipping a cup of organic tea that is grown in Hawaii. It is lightly infused with a strawberry flavor. I do not normally care for infused flavored teas. I prefer natural tea and natural flavors. However, this tea has a nice bouquet with a hint of fruit on the palate with a subtle finish. It goes well with the oatmeal, apple, and walnut cookies the Scripting Wife made. She uses extra apples for a natural sweetness in her own recipe that does not call for any flour or sugar. Instead of flour, she used crushed walnuts. How about that? A totally healthy cookie. I enjoy drinking Hawaii tea, particular when it is cold outside. I close my eyes, and I feel a mountain breeze. I can hear the roar of the waterfall. I am on Kauai with my laptop, writing a Windows PowerShell script and enjoying the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Wailua_Falls\"><font face=\"Segoe\">Wailua Falls<\/font><\/a>:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of Wailua Falls\" alt=\"Image of Wailua Falls\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0121\/hsg-01-21-10-01.jpg\" width=\"480\" height=\"640\"><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">SL, let us start at the beginning. The first thing you will probably want to do is create a module. You can create a module in the Windows PowerShell ISE. One of the first things to do is to locate a couple of functions you wish to store in the module; you can copy them directly into the Windows PowerShell ISE, as seen in this image.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of functions in Windows PowerShell ISE\" alt=\"Image of functions in Windows PowerShell ISE\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0121\/hsg-01-21-10-02.jpg\" width=\"700\" height=\"546\"><\/p>\n<p class=\"Fig-Graphic\">&nbsp;<\/p>\n<p class=\"MsoNormal\">After you have copied your functions into the new module, save the module with the .PSM1 extension. The basicFunctions.psm1 module is seen here. <\/p>\n<p class=\"MsoNormal\"><strong>BasicFunctions.psm1<\/p>\n<p><\/strong><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Function Get-OptimalSize<br \/>{<br \/><span>&nbsp;<\/span>&lt;#<br \/><span>&nbsp; <\/span>.Synopsis<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Converts Bytes into the appropriate unit of measure. <br \/><span>&nbsp;&nbsp; <\/span>.Description<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>The Get-OptimalSize function converts bytes into the appropriate unit of <br \/><span>&nbsp;&nbsp;&nbsp; <\/span>measure. It returns a string representation of the number.<br \/><span>&nbsp;&nbsp; <\/span>.Example<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Get-OptimalSize 1025<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Converts 1025 bytes to 1.00 KiloBytes<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>.Example<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Get-OptimalSize -sizeInBytes 10099999 <br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Converts 10099999 bytes to 9.63 MegaBytes<br \/><span>&nbsp;&nbsp; <\/span>.Parameter SizeInBytes<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>The size in bytes to be converted<br \/><span>&nbsp;&nbsp; <\/span>.Inputs<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>[int64]<br \/><span>&nbsp;&nbsp; <\/span>.OutPuts<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>[string]<br \/><span>&nbsp;&nbsp; <\/span>.Notes<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>NAME:<span>&nbsp; <\/span>Get-OptimalSize<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>AUTHOR: Ed Wilson<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>LASTEDIT: 1\/4\/2010<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>KEYWORDS:<br \/><span>&nbsp;&nbsp; <\/span>.Link<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Http:\/\/www.ScriptingGuys.com<br \/><span>&nbsp;<\/span>#Requires -Version 2.0<br \/><span>&nbsp;<\/span>#&gt;<br \/>[CmdletBinding()]<br \/>param(<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>[Parameter(Mandatory = $true,Position = 0,valueFromPipeline=$true)]<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>[int64]<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$sizeInBytes<br \/>) #end param<br \/><span>&nbsp;<\/span>Switch ($sizeInBytes) <br \/><span>&nbsp; <\/span>{<br \/><span>&nbsp;&nbsp; <\/span>{$sizeInBytes -ge 1TB} {&#8220;{0:n2}&#8221; -f<span>&nbsp; <\/span>($sizeInBytes\/1TB) + &#8221; TeraBytes&#8221;;break}<br \/><span>&nbsp;&nbsp; <\/span>{$sizeInBytes -ge 1GB} {&#8220;{0:n2}&#8221; -f<span>&nbsp; <\/span>($sizeInBytes\/1GB) + &#8221; GigaBytes&#8221;;break}<br \/><span>&nbsp;&nbsp; <\/span>{$sizeInBytes -ge 1MB} {&#8220;{0:n2}&#8221; -f<span>&nbsp; <\/span>($sizeInBytes\/1MB) + &#8221; MegaBytes&#8221;;break}<br \/><span>&nbsp;&nbsp; <\/span>{$sizeInBytes -ge 1KB} {&#8220;{0:n2}&#8221; -f<span>&nbsp; <\/span>($sizeInBytes\/1KB) + &#8221; KiloBytes&#8221;;break}<br \/><span>&nbsp;&nbsp; <\/span>Default { &#8220;{0:n2}&#8221; -f $sizeInBytes + &#8221; Bytes&#8221; }<br \/><span>&nbsp; <\/span>} #end switch<br \/><span>&nbsp; <\/span>$sizeInBytes = $null<br \/>} #end Function Get-OptimalSize <\/p>\n<p>Function Get-ComputerInfo<br \/>{<br \/><span>&nbsp;<\/span>&lt;#<br \/><span>&nbsp; <\/span>.Synopsis<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Retrieves basic information about a computer. <br \/><span>&nbsp;&nbsp; <\/span>.Description<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>The Get-ComputerInfo cmdlet retrieves basic information such as<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>computer name, domain name, and currently logged on user from<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>a local or remote computer.<br \/><span>&nbsp;&nbsp; <\/span>.Example<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Get-ComputerInfo <br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Returns comptuer name, domain name and currently logged on user<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>from local computer.<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>.Example<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Get-ComputerInfo -computer berlin<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Returns comptuer name, domain name and currently logged on user<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>from remote computer named berlin.<br \/><span>&nbsp;&nbsp; <\/span>.Parameter Computer<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Name of remote computer to retrieve information from<br \/><span>&nbsp;&nbsp; <\/span>.Inputs<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>[string]<br \/><span>&nbsp;&nbsp; <\/span>.OutPuts<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>[object]<br \/><span>&nbsp;&nbsp; <\/span>.Notes<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>NAME:<span>&nbsp; <\/span>Get-ComputerInfo<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>AUTHOR: Ed Wilson<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>LASTEDIT: 1\/11\/2010<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>KEYWORDS:<br \/><span>&nbsp;&nbsp; <\/span>.Link<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Http:\/\/www.ScriptingGuys.com<br \/><span>&nbsp;<\/span>#Requires -Version 2.0<br \/><span>&nbsp;<\/span>#&gt;<br \/><span>&nbsp;<\/span>Param([string]$computer=&#8221;localhost&#8221;)<br \/><span>&nbsp;<\/span>$wmi = Get-WmiObject -Class win32_computersystem -ComputerName $computer<br \/><span>&nbsp;<\/span>$pcinfo = New-Object -TypeName system.object<br \/><span>&nbsp;<\/span>$pcInfo | Add-Member -MemberType noteproperty -Name host -Value $($wmi.DNSHostname)<br \/><span>&nbsp;<\/span>$pcInfo | Add-Member -MemberType noteproperty -Name domain -Value $($wmi.Domain)<br \/><span>&nbsp;<\/span>$pcInfo | Add-Member -MemberType noteproperty -Name user -Value $($wmi.Username)<br \/><span>&nbsp;<\/span>$pcInfo<br \/>}<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">You can control what is exported from the module by creating a manifest. If you place related functions that you will more than likely want to use together, you can avoid creating a manifest. In the BasicFunctions.psm1 module, there are two functions, one of which was created during <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/01\/14\/hey-scripting-guy-january-14-2010.aspx\">Microsoft Visio Week<\/a>.<\/p>\n<p class=\"MsoNormal\">The <b>Get-ComputerInfo<\/b> function was written for today&rsquo;s Hey, Scripting Guy! post and is used to return a custom object that contains information about the user, computer name, and computer domain. After you have created and saved the module, you will need to install the module. You can do this manually by navigating to the module directory, creating a folder for the module, and placing a copy of the module in the folder. I prefer to use the Copy-Modules.ps1 script that was discussed on <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/01\/19\/hey-scripting-guy-january-19-2010.aspx\">Tuesday<\/a>. <\/p>\n<p class=\"MsoNormal\">After the module has been copied to its own directory, you can use the <b>Import-Module<\/b> cmdlet to import it into the current Windows PowerShell session. If you are not sure of the name of the module, you can use the <b>Get-Module<\/b> cmdlet with the <b>&ndash;ListAvailable<\/b> switch, as seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-Module -ListAvailable<\/p>\n<p>ModuleType Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>ExportedCommands<br \/>&#8212;&#8212;&#8212;- &#8212;-<span>&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;&#8212;&#8212;-<br \/>Script<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>BasicFunctions<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Script<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DotNet<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>FileSystem<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>IsePack<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>PowerShellPack<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>PSCodeGen<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>PSImageTools<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>PSRSS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>PSSystemTools<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>PSUserTools<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>TaskScheduler<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>WPK<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>ActiveDirectory<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>AppLocker<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>BitsTransfer<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>FailoverClusters<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>GroupPolicy<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>NetworkLoadBalancingCl&#8230; {}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>PSDiagnostics<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<br \/>Manifest<span>&nbsp;&nbsp; <\/span>TroubleshootingPack<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{}<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After you have imported the module, you can use the <b>Get-Command<\/b> cmdlet with the <b>&ndash;module<\/b> parameter to see which commands are exported by the module. This is illustrated in the following image.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of using Get-Command cmdlet with -module parameter\" alt=\"Image of using Get-Command cmdlet with -module parameter\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0121\/hsg-01-21-10-03.jpg\" width=\"781\" height=\"551\"><\/p>\n<p class=\"Fig-Graphic\">&nbsp;<\/p>\n<p class=\"MsoNormal\">After you have added the functions from the module, you can use them directly from the Windows PowerShell prompt. Using the <b>Get-ComputerInfo<\/b> function is illustrated here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-ComputerInfo<\/p>\n<p>host<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>domain<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; <\/span>user<br \/>&#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; <\/span>&#8212;&#8212;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;<\/span>&#8212;-<br \/>mred1<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; <\/span>NWTraders.Com<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; <\/span>NWTRADERSed<\/p>\n<p>PS C:&gt; (Get-ComputerInfo).user<br \/>NWTRADERSed<br \/>PS C:&gt; (Get-ComputerInfo).host<br \/>mred1<br \/>PS C:&gt; Get-ComputerInfo -computer win7-pc | Format-Table -AutoSize<\/p>\n<p>host<span>&nbsp;&nbsp;&nbsp; <\/span>domain<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>user<br \/>&#8212;-<span>&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<br \/>win7-PC NWTraders.Com NWTRADERSAdministrator<\/p>\n<p>PS C:&gt;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Because the help tags were used when creating the functions, you can use the <b>Get-Help<\/b> cmdlet to obtain information about using the function. In this manner, the function that was created in the module behaves exactly like a regular Windows PowerShell cmdlet. This includes tab expansion. <\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-Help Get-ComputerInfo<\/p>\n<p>NAME<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Get-ComputerInfo<\/p>\n<p>SYNOPSIS<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Retrieves basic information about a computer.<\/p>\n<p>SYNTAX<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Get-ComputerInfo [[-computer] &lt;String&gt;] [&lt;CommonParameters&gt;]<\/p>\n<p>DESCRIPTION<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>The Get-ComputerInfo cmdlet retrieves basic information such as<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>computer name, domain name, and currently logged on user from<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>a local or remote computer.<\/p>\n<p>RELATED LINKS<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Http:\/\/www.ScriptingGuys.com<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>#Requires -Version 2.0<\/p>\n<p>REMARKS<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>To see the examples, type: &#8220;get-help Get-ComputerInfo -examples&#8221;.<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>For more information, type: &#8220;get-help Get-ComputerInfo -detailed&#8221;.<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>For technical information, type: &#8220;get-help Get-ComputerInfo -full&#8221;.<\/p>\n<p>PS C:&gt; Get-Help Get-ComputerInfo -Examples<\/p>\n<p>NAME<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Get-ComputerInfo<\/p>\n<p>SYNOPSIS<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>Retrieves basic information about a computer.<\/p>\n<p><span>&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; EXAMPLE 1 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p><span>&nbsp;&nbsp;&nbsp; <\/span>C:PS&gt;Get-ComputerInfo<\/p>\n<p><span>&nbsp;&nbsp;&nbsp; <\/span>Returns comptuer name, domain name and currently logged on user<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>from local computer.<\/p>\n<p><span>&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; EXAMPLE 2 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p><span>&nbsp;&nbsp;&nbsp; <\/span>C:PS&gt;Get-ComputerInfo -computer berlin<\/p>\n<p><span>&nbsp;&nbsp;&nbsp; <\/span>Returns comptuer name, domain name and currently logged on user<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>from remote computer named berlin.<\/p>\n<p>PS C:&gt;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The <b>Get-OptimalSize<\/b> function can even receive input from the pipeline, as shown here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; (get-WmiObject win32_volume -Filter &#8220;driveletter = &#8216;c:'&#8221;).freespace<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">26513960960<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; (get-WmiObject win32_volume -Filter &#8220;driveletter = &#8216;c:'&#8221;).freespace | Get-OptimalSize<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">24.69 GigaBytes<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Pretty cool, huh? Okay, SL, here are the steps:<\/p>\n<p class=\"BullList\"><span><span>1.<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Place functions into a module, and save it with a .psm1 extension.<\/p>\n<p class=\"BullList\"><span><span>2.<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Copy the module to the modules directory. Use the Copy-Modules.ps1 script to do this.<\/p>\n<p class=\"BullList\"><span><span>3.<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Obtain a list of available modules by using the <b>Get-Modules<\/b> cmdlet with the <b>&ndash;listavailable<\/b> switched parameter.<\/p>\n<p class=\"BullList\"><span><span>4.<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Import modules into your current Windows PowerShell session by using the <b>Import-Module<\/b> cmdlet.<\/p>\n<p class=\"BullList\"><span><span>5.<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>See which commands are available from the module by using the <b>Get-Command<\/b> cmdlet with the <b>&ndash;module<\/b> parameter.<\/p>\n<p class=\"BullList\"><span><span>6.<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Use the <b>Get-Help<\/b> cmdlet to obtain information about the exported functions.<\/p>\n<p class=\"BullList\"><span><span>7.<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Use the functions like you would use any other cmdlet. <\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">SL, that is all there is to installing and using a Windows PowerShell module. And this concludes Windows PowerShell Module Week. Join us tomorrow for Quick-Hits Friday. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be discussing tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\"><font face=\"Segoe\">Facebook<\/font><\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\"><font face=\"Segoe\">Official Scripting Guys Forum<\/font><\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\">&nbsp;\n<b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/b><\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey, Scripting Guy! I am still a bit confused about how modules work. Could you give a beginning-to-end scenario and go through the steps of creating a module, installing the module, and then using the module? &#8212; SL &nbsp; Hello, SL. Microsoft Scripting Guy Ed Wilson here. I am sipping a cup of organic [&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,52,3,4,45],"class_list":["post-51513","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-modules","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey, Scripting Guy! I am still a bit confused about how modules work. Could you give a beginning-to-end scenario and go through the steps of creating a module, installing the module, and then using the module? &#8212; SL &nbsp; Hello, SL. Microsoft Scripting Guy Ed Wilson here. I am sipping a cup of organic [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51513","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=51513"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51513\/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=51513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}