Avatar of Exchange Noob
Exchange Noob
 asked on

Enable Windows Features using Group Policy

Hi,

I need to turn on the Windows Media Player Feature in Windows 10 for a large number of domain joined computers.

I know how to do it manually via 'Control Panel - Add Windows Features' and have found articles describing how to enable this feature via PowerShell or Command Prompt.

My question is how to do this via Group Policy. I've tried a number of different ways eg. creating a batch file and adding it to the Logon GPO, running PowerShell via GPO etc but nothing seems to be working. Not sure if this is because users are not local admins?

Has anyone done something like this before and can you please point me in the right direction?
Thanks
PowershellWindows 10* grouppolicyWindows OS

Avatar of undefined
Last Comment
Michal Dsousa

8/22/2022 - Mon
oBdA

You need to run it as a Computer Startup script applied to the computers in question, not as a logon script. Adding features requires elevation.
The script should be as easy as
If ((Get-WindowsOptionalFeature -Online -FeatureName WindowsMediaPlayer).State -ne 'Enabled')
	Enable-WindowsOptionalFeature -FeatureName WindowsMediaPlayer -Online
}

Open in new window

Exchange Noob

ASKER
Hi, that's similar to what I was trying but it still doesn't work i'm afraid. I'm not sure if it's becasue of an execution policy restriction?
oBdA

If this has never been configured, then that could be a reason, yes.
Save this as Whatever.cmd and deploy it as batch (you could optionally set the executionpolicy as well, while you're at it ...):
@PowerShell.exe -Command "Invoke-Expression -Command ((Get-Content -Path '%~f0' | Select-Object -Skip 2) -join [environment]::NewLine)"
@exit /b %Errorlevel%

If ((Get-WindowsOptionalFeature -Online -FeatureName WindowsMediaPlayer).State -ne 'Enabled')
	Enable-WindowsOptionalFeature -FeatureName WindowsMediaPlayer -Online
} 

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Exchange Noob

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Michal Dsousa

hi