{"id":9739,"date":"2024-05-13T22:37:46","date_gmt":"2024-05-13T20:37:46","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=9739"},"modified":"2024-05-16T15:43:29","modified_gmt":"2024-05-16T13:43:29","slug":"powershell-create-a-powershell-module","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/powershell-create-a-powershell-module\/","title":{"rendered":"Powershell: Create a powershell module"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_9739 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_9739')){$('.twoclick_social_bookmarks_post_9739').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Powershell%3A%20Create%20a%20powershell%20module\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athis%20describes%20the%20creation%20of%20an%20powershell%20module.%0D%0A%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/powershell-create-a-powershell-module\\\/\",\"post_id\":9739,\"post_title_referrer_track\":\"Powershell%3A+Create+a+powershell+module\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>this describes the creation of an powershell module.<\/p>\n<p><!--more--><\/p>\n<p>Define a manifest and create the mainfest file by New-ModuleManifest<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\&gt; $Params = @{ \r\n\t\t&quot;Path&quot; \t\t\t\t= 'MyModule.psd1' \r\n\t\t&quot;Author&quot; \t\t\t= 'Michael' \r\n\t\t&quot;CompanyName&quot; \t\t\t= 'My Company' \r\n\t\t&quot;RootModule&quot; \t\t\t= 'MyModule.psm1' \r\n\t\t&quot;CompatiblePSEditions&quot; \t\t= @('Desktop','Core') \r\n\t\t&quot;FunctionsToExport&quot; \t\t= @('Test-Function1','Test-Function1') \r\n\t\t&quot;CmdletsToExport&quot; \t\t= @() \r\n\t\t&quot;VariablesToExport&quot; \t\t= @('myExportVariable1','myExportVariable2')\r\n\t\t&quot;AliasesToExport&quot; \t\t= @() \r\n\t\t&quot;Description&quot; = 'Description of the module' \r\n\t\t&quot;ModuleVersion&quot; = &quot;1.0.0.0&quot;\r\n\t} \r\n\r\nPS D:\\myModule&gt; New-ModuleManifest @Params\r\n<\/pre>\n<p>Create the module file MyModule.psm1<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$myExportVariable1=&quot;Test&quot;\r\n$myExportVariable2=&quot;Test&quot;\r\nfunction Test-Function1()\r\n{\r\n     write-host &quot;Function1&quot;\r\n}\r\nfunction Test-Function2()\r\n{\r\n     write-host &quot;Function2&quot;\r\n}\r\n<\/pre>\n<p>Note: The function names must begin with a valid verb otherwise a warning is shown during the load  of the module.<\/p>\n<p>Get-Verb shows a list of valid verbs<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\myModule&gt; Get-Verb\r\n<\/pre>\n<p>The try to load the module<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\myModule&gt; Import-Module .\\MyModule.psd1\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, this describes the creation of an powershell module.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344],"tags":[143,610,133],"class_list":["post-9739","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","tag-create","tag-module","tag-powershell"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=9739"}],"version-history":[{"count":4,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9739\/revisions"}],"predecessor-version":[{"id":9743,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9739\/revisions\/9743"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=9739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=9739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=9739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}