Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:08:29+00:00 2026-06-05T07:08:29+00:00

I wrote a PowerShell script for Server 2008 R2, to check if certain roles

  • 0

I wrote a PowerShell script for Server 2008 R2, to check if certain roles and features are installed and if they aren’t to install them (of course I imported the ServerManager Module at first) i.e.:

if ((Get-WindowsFeature AS-NET-Framework).Installed -eq 0)
{$InstallFeatures += "AS-NET-Framework,"
Write-Host "AS-NET-Framework will be added"}

if ((Get-WindowsFeature GPMC).Installed -eq 0)
{$InstallFeatures += "GPMC,"
 Write-Host "GPMC will be added"}

but when I invoke

Add-WindowsFeature $InstallFeatures

it gives an Error that the name wasn’t found.
Somehow PS doesn’t accept the comma as delimiter in a string.

But if you type

Add-WindowsFeature AS-NET-Framwork,GPMC

in the console it works just fine.

Is there any way to to invoke the Add-WindowsFeature with all the parameters I need in one line without creating a new variable for each check, because then I’d only need one reboot for all missing roles and features?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:08:30+00:00Added an answer on June 5, 2026 at 7:08 am

    try declaring :

     [string[]]$InstallFeatures = @()
    

    before your code.

    if ((Get-WindowsFeature AS-NET-Framework).Installed -eq 0)
    {$InstallFeatures += "AS-NET-Framework"
    Write-Host "AS-NET-Framework will be added"}
    if ((Get-WindowsFeature GPMC).Installed -eq 0)
    {$InstallFeatures += "GPMC"
     Write-Host "GPMC will be added"}
    

    The signature for Get-WindowsFeature is:

    Get-WindowsFeature [[-Name] <string[]>] [-logPath <string>] [<CommonParameters>]
    

    the parameter name accept a string array and not a string.
    In your code you need to remove the commas as I wrote above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a custom URL rewriting module, to take certain paths and map them
I have a question i wrote a powershell script so i have name.ps1, but
I wrote a simple powershell script that checks the number of tickets in a
I wrote a script to remotely fetch event logs in PowerShell, but I'm not
I wrote a simple batch file as a PowerShell script, and I am getting
I trying to write a PowerShell script (learning at the same time). I have
I'm trying to write a powershell script that updats each of the DiagnosticsConnectionString and
I am trying to write a powershell script that will take in a text
I have the following code snippet from my PowerShell script that... Loops through a
Windows Server 2008. How can I quickly use up RAM so to induce GC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.