{"id":8741,"date":"2021-12-17T10:37:24","date_gmt":"2021-12-17T15:37:24","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8741"},"modified":"2021-12-17T10:37:28","modified_gmt":"2021-12-17T15:37:28","slug":"building-a-powershell-module-inception-style","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/","title":{"rendered":"Building a PowerShell Module Inception-Style"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignleft size-full\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"390\" height=\"216\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg\" alt=\"\" class=\"wp-image-8743\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg 390w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception-300x166.jpg 300w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Over the course of the last week or so, I've been sharing PowerShell functions and scripts for working with PowerShell functions and scripts. I showed PowerShell functions to export functions to a script file and code to convert scripts to functions It has all been very <a href=\"https:\/\/www.imdb.com\/title\/tt1375666\/\" target=\"_blank\" rel=\"noreferrer noopener\">Inception<\/a>-like. To wrap this all up I thought I'd share a PowerShell script I wrote to convert all of the code I've been sharing into a new module. I will eventually publish PSFunctionTools to the PowerShell Gallery and I see no reason why it won't work in Windows PowerShell or PowerShell 7. Even cross-platform. <\/p>\n\n\n\n<p>The script might even be the basis for an additional function. Or I might include it as a reference sample in the new module. What is mind-bending to me is that I am using the functions in the code on themselves to create something new. I don't expect you to be able to run this script since it is written for my environment and files. I've posted all of the code over the last week, but my files may be different than yours.<\/p>\n\n\n\n<p>This script is based on the one I <a href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8709\/converting-powershell-scripts-to-functions\/\" target=\"_blank\" rel=\"noreferrer noopener\">posted as a proof-of-concept for converting scripts<\/a> into a PowerShell module. My script will also initialize the new project in git and generate initial help documentation using the <a href=\"https:\/\/github.com\/PowerShell\/platyPS\" target=\"_blank\" rel=\"noreferrer noopener\">Platyps <\/a>module.<\/p>\n\n\n\n<pre title=\"New-PSFunctionToolsModule.ps1\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#requires -version 5.1\n#requires -module Platyps\n\n#Export functions from files and create a new module\n\n[cmdletbinding(SupportsShouldProcess)]\nParam(\n    [Parameter(position = 0,HelpMessage = \"What is the name of the new module?\")]\n    [ValidateNotNullOrEmpty()]\n    [string]$NewModuleName = \"PSFunctionTools\",\n\n    [Parameter(Position = 1,HelpMessage = \"What is the parent path for the new module?\")]\n    [ValidateNotNullOrEmpty()]\n    [ValidateScript({Test-Path $_})]\n    [string]$ParentPath = \"C:\\Scripts\",\n\n    [Parameter(HelpMessage = \"Enter an module description.\")]\n    [string]$Description = \"A set of PowerShell commands for working with PowerShell scripts and functions.\",\n\n    [Parameter(HelpMessage =\"PowerShell script files with functions to export.\")]\n    [ValidateNotNullOrEmpty()]\n    [ValidateScript({Test-Path $_})]\n    [string[]]$Files = $(\n        'C:\\scripts\\Convert-FunctionToFile.ps1',\n        'C:\\scripts\\new-folderlayout.ps1',\n        'C:\\scripts\\dev-scripttofunction.ps1'\n        )\n)\n\nWrite-Verbose \"Starting $($MyInvocation.MyCommand)\"\n\n&lt;#\ndot source the conversion functions\n\nC:\\scripts\\Convert-FunctionToFile.ps1\n  Test-FunctionName\n  Get-FunctionName\n  Get-FunctionAlias\n  Export-FunctionFromFile\nC:\\scripts\\New-FolderLayout.ps1\n  Import-ModuleLayout\n  Export-ModuleLayout\n#>\n. C:\\scripts\\Convert-FunctionToFile.ps1\n. C:\\scripts\\New-FolderLayout.ps1\n\n#the new module location\n$path = Join-path -Path $ParentPath -ChildPath $NewModuleName\n$export = [System.Collections.Generic.list[object]]::New()\n$aliases = @()\n#the layout was created using Export-ModuleLayout\n$layout = \"C:\\scripts\\ModuleLayout.json\"\nWrite-Verbose \"Creating the module structure\"\nImport-ModuleLayout -Name $NewModuleName -ParentPath $ParentPath -Layout $layout\n\n#I removed the parameter validation on the target path\n$functionFiles = $files | ForEach-Object {\n    Write-Verbose \"Processing $_\"\n    Export-FunctionFromFile -Path $_ -OutputPath $Path\\functions\\public -All -Passthru\n    #get aliases\n    if ($pscmdlet.ShouldProcess($_,\"Getting function aliases\")) {\n        $aliases += Get-FunctionAlias -path $_ | Select-Object -ExpandProperty alias\n    }\n}\n\nif ($functionFiles) {\n    $export.AddRange($functionFiles.baseName)\n}\n\n#create the root module\n$psm1 = @\"\n\nGet-Childitem `$psscriptroot\\functions\\*.ps1 -recurse |\nForeach-Object {\n. `$_.FullName\n}\n\n\"@\nWrite-Verbose \"Creating root module $path\\$newmodulename.psm1\"\n$psm1 | Out-File \"$path\\$newmodulename.psm1\"\n\n#create the module manifest\n$splat = @{\n    Path                 = \"$path\\$newmodulename.psd1\"\n    RootModule           = \"$newmodulename.psm1\"\n    ModuleVersion        = \"0.1.0\"\n    Author               = \"Jeff Hicks\"\n    CompanyName          = \"JDH Information Technology Solutions, Inc.\"\n    Copyright            = \"(c) 2021 JDH Information Technology Solutions, Inc.\"\n    Description          = $Description\n    CmdletsToExport      = @()\n    VariablesToExport    = @()\n    FunctionsToExport    = $Export\n    AliasesToExport      = $aliases\n    PowerShellVersion    = \"5.1\"\n    CompatiblePSEditions = \"Desktop\",\"Core\"\n}\nWrite-Verbose \"Creating module manifest $($splat.path)\"\nNew-ModuleManifest @splat\n\n#this requires the Platyps module\nWrite-Verbose \"Creating module help files\"\nif ($PSCmdlet.ShouldProcess(\"docs\",\"create markdown help files\")) {\n    Import-Module $splat.path\n    New-MarkdownHelp -Module $NewModuleName -OutputFolder $path\\docs\n    New-ExternalHelp -Path $path\\docs -OutputPath $path\\en-us\n}\n\nWrite-Verbose \"Initializing git\"\nif ($PSCmdlet.ShouldProcess($path, \"git initialize\")) {\n    Set-Location $path\n    git init\n    git add .\n    git commit -m \"initial files\"\n    git checkout -b $splat.ModuleVersion\n}\n\nif (-not $WhatIfPreference) {\n    Get-ChildItem $path -Recurse\n    Try {\n        [void](Get-Command -name code.cmd -ErrorAction stop)\n        Write-Verbose \"Opening module in VSCode\"\n        code $path\n    }\n    Catch {\n        Write-Warning \"VS Code not found.\"\n    }\n}\n\nWrite-Verbose \"Ending $($MyInvocation.MyCommand)\"<\/code><\/pre>\n\n\n\n<p>I've parameterized the script with the idea that I can turn this into a reusable tool. But for now, the parameter values are hard-coded to save me typing. <\/p>\n\n\n\n<p>The script has several phases. First, it creates the module structure using the command I shared to export and import a model module directory structure. Second, the script takes the array of files and exports all of the functions to separate files. Third, it creates a root module, and the module manifest using information from the exported functions. Next, the script creates help documentation and finally initializes git. If I'm not running the script with -WhatIf, the new module will be opened in VSCode.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"509\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif-1024x509.png\" alt=\"new-psfunctiontoolsmodule script with -Whatif\" class=\"wp-image-8744\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif-1024x509.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif-300x149.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif-768x381.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif-1536x763.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif-850x422.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-module-whatif.png 1786w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>I've already run this script and started working on the module, but I wanted you to see the output so this is using a temporary folder and -Whatif. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/module-invscode.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/module-invscode-1024x768.png\" alt=\"new module in vs code\" class=\"wp-image-8745\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/module-invscode-1024x768.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/module-invscode-300x225.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/module-invscode-768x576.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/module-invscode-850x638.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/module-invscode.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Here you can see the results in VSCode. The entire process took about 3 seconds. I definitely will be developing this idea and using it myself. I often start with standalone script files that eventually I decide to turn into modules. It will be nice to have a set of tools to accelerate that process.<\/p>\n\n\n\n<p>In the meantime, feel free to use any of the code I've shared to build your own PowerShell tooling for building PowerShell tooling.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the course of the last week or so, I&#8217;ve been sharing PowerShell functions and scripts for working with PowerShell functions and scripts. I showed PowerShell functions to export functions to a script file and code to convert scripts to functions It has all been very Inception-like. To wrap this all up I thought I&#8217;d&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: Building a #PowerShell module Inception-Style","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8],"tags":[221,534,540],"class_list":["post-8741","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-module","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Building a PowerShell Module Inception-Style &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"Here&#039;s how I quickly built a PowerShell module using the commands I want to build the new module around with a PowerShell script.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building a PowerShell Module Inception-Style &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Here&#039;s how I quickly built a PowerShell module using the commands I want to build the new module around with a PowerShell script.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-17T15:37:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-17T15:37:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Building a PowerShell Module Inception-Style\",\"datePublished\":\"2021-12-17T15:37:24+00:00\",\"dateModified\":\"2021-12-17T15:37:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/\"},\"wordCount\":452,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/psinception.jpg\",\"keywords\":[\"module\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/\",\"name\":\"Building a PowerShell Module Inception-Style &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/psinception.jpg\",\"datePublished\":\"2021-12-17T15:37:24+00:00\",\"dateModified\":\"2021-12-17T15:37:28+00:00\",\"description\":\"Here's how I quickly built a PowerShell module using the commands I want to build the new module around with a PowerShell script.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/psinception.jpg\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/psinception.jpg\",\"width\":390,\"height\":216},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8741\\\/building-a-powershell-module-inception-style\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building a PowerShell Module Inception-Style\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building a PowerShell Module Inception-Style &#8226; The Lonely Administrator","description":"Here's how I quickly built a PowerShell module using the commands I want to build the new module around with a PowerShell script.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/","og_locale":"en_US","og_type":"article","og_title":"Building a PowerShell Module Inception-Style &#8226; The Lonely Administrator","og_description":"Here's how I quickly built a PowerShell module using the commands I want to build the new module around with a PowerShell script.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/","og_site_name":"The Lonely Administrator","article_published_time":"2021-12-17T15:37:24+00:00","article_modified_time":"2021-12-17T15:37:28+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Building a PowerShell Module Inception-Style","datePublished":"2021-12-17T15:37:24+00:00","dateModified":"2021-12-17T15:37:28+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/"},"wordCount":452,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg","keywords":["module","PowerShell","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/","name":"Building a PowerShell Module Inception-Style &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg","datePublished":"2021-12-17T15:37:24+00:00","dateModified":"2021-12-17T15:37:28+00:00","description":"Here's how I quickly built a PowerShell module using the commands I want to build the new module around with a PowerShell script.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/psinception.jpg","width":390,"height":216},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8741\/building-a-powershell-module-inception-style\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Building a PowerShell Module Inception-Style"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8787,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8787\/prerelease-of-psfunctiontools-for-powershell\/","url_meta":{"origin":8741,"position":0},"title":"Prerelease of PSFunctionTools for PowerShell","author":"Jeffery Hicks","date":"January 13, 2022","format":false,"excerpt":"At the end of last year wrote a series of blog posts describing tools and techniques for working with PowerShell scripts and functions. My goal was to build a framework of tools that I could use to automate PowerShell scripting work, such as creating a new module from a group\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/psfunctiontools-commands.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/psfunctiontools-commands.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/psfunctiontools-commands.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/psfunctiontools-commands.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/psfunctiontools-commands.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/psfunctiontools-commands.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":3722,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3722\/reflections-on-the-powershell-scripting-games\/","url_meta":{"origin":8741,"position":1},"title":"Reflections on the PowerShell Scripting Games","author":"Jeffery Hicks","date":"February 26, 2014","format":false,"excerpt":"During the most recent PowerShell Scripting Games, I was fortunate enough to be one of the judges. Now that the games have concluded I thought I'd share my reflections on the entries. Naturally these are merely my opinions but they are drawn from years of experience with PowerShell and almost\u2026","rel":"","context":"In &quot;Best Practices&quot;","block_context":{"text":"Best Practices","link":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},"img":{"alt_text":"talkbubble","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1869,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1869\/add-whatif-support-to-your-powershell-scripts\/","url_meta":{"origin":8741,"position":2},"title":"Add WhatIf Support to Your PowerShell Scripts","author":"Jeffery Hicks","date":"December 2, 2011","format":false,"excerpt":"In one of my recent articles for SMB IT, I included a PowerShell module. In the article I referenced that I included support for -Whatif in one of the functions. I was asked on Twitter to explain what I meant and how it works. So here goes. There are a\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8724,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8724\/discovering-aliases-with-the-powershell-ast\/","url_meta":{"origin":8741,"position":3},"title":"Discovering Aliases with the PowerShell AST","author":"Jeffery Hicks","date":"December 15, 2021","format":false,"excerpt":"I've been working on a new PowerShell module that incorporates code from a few of my recent posts on converting PowerShell scripts and functions to files. I even whipped up a script, think of it as a meta-script, to create the module using the commands that I am adding to\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/find-alias-string.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/find-alias-string.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/find-alias-string.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/find-alias-string.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1729,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1729\/ise-scripting-geek-module\/","url_meta":{"origin":8741,"position":4},"title":"ISE Scripting Geek Module","author":"Jeffery Hicks","date":"October 27, 2011","format":false,"excerpt":"Over the last year I've posted functions I've written to extend the Windows PowerShell ISE. I have finally pulled everything together into a module I'm calling the ISE Scripting Geek. Download and extract the zip file (below) to your modules folder. You should end up with a path like 'C:\\Users\\Jeff\\Documents\\WindowsPowerShell\\Modules\\ISEScriptingGeek'.\u2026","rel":"","context":"In &quot;PowerShell ISE&quot;","block_context":{"text":"PowerShell ISE","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-ise\/"},"img":{"alt_text":"ISE Scripting Geek add-on menu","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/isescriptinggeek-300x200.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":5833,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5833\/new-powershell-projects-published\/","url_meta":{"origin":8741,"position":5},"title":"New PowerShell Projects Published","author":"Jeffery Hicks","date":"December 18, 2017","format":false,"excerpt":"Last week I published a few of the recent PowerShell modules I've been working on to the PowerShell Gallery. These projects had been in a beta phase while I worked out some last minute features. I was also waiting to see if there were any issues reported by you that\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-6.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-6.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-6.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8741"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8741\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}