# Install nuget and DSC modules via script

**URL:** https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873
**Category:** DSC
**Created:** [March 6, 2021, 12:06am UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873 "2021-03-06T00:06:27Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![monterey610](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/monterey610/32/1080_2.png) [@monterey610](https://forums.powershell.org/u/monterey610)
#### Post date: [March 6, 2021, 12:06am UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/1 "2021-03-06T00:06:27Z")

</div>

I am trying to install DSC Module on a basic Windows 2019 Server. It just fails silently. This is a brand new servers that are failing

```auto
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if(!(get-packageprovider -name nuget)){
    Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force -Scope CurrentUser
  }

Set-PSRepository -Name 'PsGallery' -InstallationPolicy Trusted
Install-Module -Name NetworkingDsc -RequiredVersion 8.1.0 -AllowClobber -Repository PSGallery -Verbose

```

---

<div class="post-metadata">

### Author: ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)
#### Post date: [March 7, 2021, 3:07pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/2 "2021-03-07T15:07:23Z")

</div>

What is the error you are getting ?

---

<div class="post-metadata">

### Author: ![monterey610](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/monterey610/32/1080_2.png) [@monterey610](https://forums.powershell.org/u/monterey610)
#### Post date: [March 7, 2021, 3:57pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/3 "2021-03-07T15:57:19Z")

</div>

No error. It just fails silently

---

<div class="post-metadata">

### Author: ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)
#### Post date: [March 7, 2021, 4:22pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/4 "2021-03-07T16:22:21Z")

</div>

use `-ErrorAction Stop` for all the cmdlets. It should fail, else its wont be easy to find the reason.

---

<div class="post-metadata">

### Author: ![dan-iverson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-iverson/32/11_2.png) [@dan-iverson](https://forums.powershell.org/u/dan-iverson)
#### Post date: [May 14, 2021, 9:17pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/5 "2021-05-14T21:17:28Z")

</div>

I am getting these errors:

`
Exception calling "ShouldContinue" with "2" argument(s): "Windows PowerShell 
is in NonInteractive mode. Read and Prompt functionality is not available."
At C:\Program 
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7392 char:8
+ if($Force -or $psCmdlet.ShouldContinue($shouldContinueQueryMessag ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PSInvalidOperationException
Set-PSRepository : NuGet provider is required to interact with NuGet-based
repositories. Please ensure that ‘2.8.5.201’ or newer version of NuGet
provider is installed.
At C:\ProgramData\Amazon\SSM\InstanceData\i-015ccaaf3fcfd076a\document\orchestr
ation\800b245a-c7c4-4340-943a-bdea231b4760\runPowerShellScript_script.ps1:7
char:5

```
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted

```

```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```

CategoryInfo : InvalidOperation: (🙂 [Set-PSRepository], Invali
dOperationException
FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Set-PSRepository

Get-PackageProvider : Unable to find package provider ‘Nuget’.
At C:\ProgramData\Amazon\SSM\InstanceData\i-015ccaaf3fcfd076a\document\orchestr
ation\800b245a-c7c4-4340-943a-bdea231b4760\runPowerShellScript_script.ps1:11
char:7
`
`
If ( (Get-PackageProvider -Name Nuget -ListAvailable).Version -le 2.8 …
`- `
```
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```
`
`
CategoryInfo : ObjectNotFound: (Microsoft.Power…PackageProvid
er:GetPackageProvider) [Get-PackageProvider], Exception
` - `FullyQualifiedErrorId : UnknownProvider,Microsoft.PowerShell.PackageMana
gement.Cmdlets.GetPackageProvider
`

---

<div class="post-metadata">

### Author: ![dan-iverson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-iverson/32/11_2.png) [@dan-iverson](https://forums.powershell.org/u/dan-iverson)
#### Post date: [May 14, 2021, 9:18pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/6 "2021-05-14T21:18:52Z")

</div>

I am trying to run this script:  
`
“Import-Module -Name PowerShellGet -Force\n”,
“Import-Module -Name PackageManagement -Force\n”,
“if ( (Get-PSRepository -Name ‘PSGallery’).InstallationPolicy -eq ‘Untrusted’ ) {\n”,
" Set-PSRepository -Name ‘PSGallery’ -InstallationPolicy Trusted \n",
“}\n”,
“If ( (Get-PackageProvider -Name Nuget -ListAvailable).Version -le 2.8.5.208 ) {\n”,
" Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force\n",
“}\n”,
“if ( -not ( Get-Module -Name PSDscResources -ListAvailable ) ) {\n”,
" Install-Module PSDscResources -AllowClobber -SkipPublisherCheck -Confirm:$false -Force\n",
“}\n”,
“if ( -not ( Get-Module -Name PSDscResources ) ) {\n”,
" Import-Module -Name PSDscResources -Global -Force -PassThru \n",
“}\n\n”
`

---

<div class="post-metadata">

### Author: ![dan-iverson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-iverson/32/11_2.png) [@dan-iverson](https://forums.powershell.org/u/dan-iverson)
#### Post date: [May 15, 2021, 3:13am UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/7 "2021-05-15T03:13:32Z")

</div>

I think I got it:

```auto
                    "Import-Module -Name PowerShellGet -Force\n",
                    "Import-Module -Name PackageManagement -Force\n",
                    "try {\n",
                    " If ( (Get-PackageProvider -Name Nuget -ListAvailable -ErrorAction Stop ).Version -le 2.8.5.208 ) {\n",
                    " Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force\n",
                    " }\n",
                    "} catch {\n",
                    " Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force\n",
                    "}\n",
                    "if ( (Get-PSRepository -Name 'PSGallery').InstallationPolicy -eq 'Untrusted' ) {\n",
                    " Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted \n",
                    "}\n",
                    "if ( -not ( Get-Module -Name PSDscResources -ListAvailable ) ) {\n",
                    " Install-Module PSDscResources -AllowClobber -SkipPublisherCheck -Confirm:$false -Force\n",
                    "}\n",
                    "if ( -not ( Get-Module -Name PSDscResources ) ) {\n",
                    " Import-Module -Name PSDscResources -Global -Force -PassThru \n",
                    "}\n\n",

```

---

<div class="post-metadata">

### Author: ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)
#### Post date: [May 15, 2021, 1:33pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/8 "2021-05-15T13:33:56Z")

</div>

> [@dan-iverson](#):
>
> I think I got it:

Could you please format your codse as code here in the forum? You can go back and edit your already existing posts to correct the formatting.

Thanks in advacne.

---

<div class="post-metadata">

### Author: ![dan-iverson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-iverson/32/11_2.png) [@dan-iverson](https://forums.powershell.org/u/dan-iverson)
#### Post date: [May 18, 2021, 2:14pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/9 "2021-05-18T14:14:21Z")

</div>

It is in “` <\code>” blocks.`

---

<div class="post-metadata">

### Author: ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)
#### Post date: [May 18, 2021, 4:08pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/10 "2021-05-18T16:08:51Z")

</div>

I don’t know how it looks for you but for me it does not look like code at all. 😉

Do you see any difference between one of your code blocks and the code block @monterey610 posted in his initial question? 😉 😉

---

<div class="post-metadata">

### Author: ![dan-iverson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-iverson/32/11_2.png) [@dan-iverson](https://forums.powershell.org/u/dan-iverson)
#### Post date: [May 21, 2021, 6:13pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/11 "2021-05-21T18:13:04Z")

</div>

`
Yes, I see the difference, his is PowerShell and mine is JSON.
`

---

<div class="post-metadata">

### Author: ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)
#### Post date: [May 21, 2021, 6:29pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/12 "2021-05-21T18:29:34Z")

</div>

No.

His looks like correctly formated code including syntax highlighting and indentation

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/f/f7d3d78eda4a222f53ca5598506aeeaaa7ecb348.png)

And yours just does not.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/4/48ea64a1b0fe263a056005ca36ff74cf4fdfd6f3.png)

---

<div class="post-metadata">

### Author: ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)
#### Post date: [May 22, 2021, 12:16pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/13 "2021-05-22T12:16:22Z")

</div>

@dan-iverson I’ve formatted the json content. The best way to format is , once the code is pasted/typed while posting, select all the code and click on the prefrmatted text button (the sixth option in the tool bar on top while posting)

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 9:14pm UTC](https://forums.powershell.org/t/install-nuget-and-dsc-modules-via-script/15873/14 "2024-05-16T21:14:13Z")

</div>


