{"id":1616,"date":"2021-05-10T20:53:06","date_gmt":"2021-05-11T03:53:06","guid":{"rendered":"http:\/\/blog.nillsf.com\/?p=1616"},"modified":"2021-05-10T20:53:12","modified_gmt":"2021-05-11T03:53:12","slug":"how-to-install-powershell-modules-in-a-visual-studio-code-devcontainer","status":"publish","type":"post","link":"https:\/\/blog.nillsf.com\/index.php\/2021\/05\/10\/how-to-install-powershell-modules-in-a-visual-studio-code-devcontainer\/","title":{"rendered":"How to install PowerShell modules in a Visual Studio Code devcontainer"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I&#8217;m doing a fair bit of work lately in VS Code devcontainers. They are an amazing way to create consistent development environments without having to install tools locally.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I ran into an issue building PowerShell Docker images with modules installed (I specifically needed to install Az PowerShell, the Az ResourceGraph PowerShell module and Pester). Simple running install-module $name -force didn&#8217;t do the trick. Below is an example of a Dockerfile for a devcontainer with all the right modules installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ARG VARIANT=7\n\nFROM mcr.microsoft.com\/azure-functions\/powershell:3.0-powershell${VARIANT}-core-tools\n\nRUN pwsh -Command Set-PSRepository -Name PSGallery -InstallationPolicy Trusted &amp;&amp; \\\n    pwsh -Command Install-Module -Name Az -Scope AllUsers -Repository PSGallery &amp;&amp; \\\n    pwsh -Command Install-Module -Name Az.ResourceGraph -Scope AllUsers -Repository PSGallery &amp;&amp; \\\n    pwsh -Command Install-Module -Name Pester -Scope AllUsers -Repository PSGallery &amp;&amp; \\\n    pwsh -Command Set-PSRepository -Name PSGallery -InstallationPolicy Untrusted\n\nCMD &#91; \"pwsh\" ]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m doing a fair bit of work lately in VS Code devcontainers. They are an amazing way to create consistent development environments without having to install tools locally. I ran into an issue building PowerShell Docker images with modules installed (I specifically needed to install Az PowerShell, the Az ResourceGraph PowerShell module and Pester). Simple [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1617,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[128,86,182,112,183],"class_list":["post-1616","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-containers","tag-docker","tag-pester","tag-powershell","tag-vistual-studio-code"],"jetpack_featured_media_url":"https:\/\/nillsfblog.blob.core.windows.net\/media\/2021\/05\/2021-05-10-20_51_35-Customize-core-dumps-in-Azure-Kubernetes.pptx-Microsoft-PowerPoint-Online-and-.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/1616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/comments?post=1616"}],"version-history":[{"count":1,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/1616\/revisions"}],"predecessor-version":[{"id":1618,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/1616\/revisions\/1618"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/media\/1617"}],"wp:attachment":[{"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/media?parent=1616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/categories?post=1616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nillsf.com\/index.php\/wp-json\/wp\/v2\/tags?post=1616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}