deploy powershell script

Rising Flight 4,036 Reputation points
2024-03-28T00:29:02.8933333+00:00

Hi All

i want to deploy the below PowerShell script on a collection. When i execute below syntax manually on a VM, it will give me the prompt to install NuGet. I want to add YES in the PowerShell script so that it will not prompt and script will not fail. How can i add it please guide me.

(PowershellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositores.Do you want PowerShellGet to install and import the NuGet provider now?)(Yes/No/Suspend)

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Install PSWindowsUpdate module if not already installed
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
    Write-Host "Installing PSWindowsUpdate module..."
    Install-Module PSWindowsUpdate -Force
}
else {
    Write-Host "PSWindowsUpdate module is already installed."
}
# Import PSWindowsUpdate module
Import-Module PSWindowsUpdate
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,443 questions
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Deployment: The process of delivering, assembling, and maintaining a particular version of a software system at a site.
924 questions
Microsoft Configuration Manager Application
Microsoft Configuration Manager Application
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Application: A computer program designed to carry out a specific task other than one relating to the operation of the computer itself, typically to be used by end users.
466 questions
Microsoft Configuration Manager
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,255 questions
0 comments No comments
{count} votes

Accepted answer
  1. AllenLiu-MSFT 42,186 Reputation points Microsoft Vendor
    2024-03-28T02:10:26.1333333+00:00

    Hi, @Rising Flight

    Thank you for posting in Microsoft Q&A forum.

    To install the NuGet provider without being prompted, you can use the -Force parameter with the Install-PackageProvider cmdlet. Here's an updated version of your script that includes this change:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    # Install NuGet provider if not already installed
    if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
        Write-Host "Installing NuGet provider..."
        Install-PackageProvider -Name NuGet -Force
    }
    else {
        Write-Host "NuGet provider is already installed."
    }
    # Install PSWindowsUpdate module if not already installed
    if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
        Write-Host "Installing PSWindowsUpdate module..."
        Install-Module PSWindowsUpdate -Force
    }
    else {
        Write-Host "PSWindowsUpdate module is already installed."
    }
    # Import PSWindowsUpdate module
    Import-Module PSWindowsUpdate
    

    This script checks if the NuGet provider is already installed and installs it if it's not. The -ErrorAction SilentlyContinue parameter prevents any error messages from being displayed if the provider is not found. The -Force parameter with Install-PackageProvider installs the provider without prompting.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Add comment".

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Gary Blok 1,736 Reputation points
    2024-03-28T03:40:35.3766667+00:00

    What are you trying to accomplish with the PSWindowsUpdate on a collection of endpoints?
    If you're trying to deploy Windows Updates, I'd recommend looking into

    1. Using Software Updates in ConfigMgr to maintain device compliance
    2. Using Co-management to use Windows Update for Business to manage your updates
    3. Using Native PowerShell commands, removing the reliance on the PSWIndowsUpdate Module
      1. https://github.com/OSDeploy/OSD/blob/master/Public/OSDCloudTS/Start-WindowsUpdate.ps1
    0 comments No comments