<# .Synopsis Enable and disable Windows Features on a client .DESCRIPTION This script creates a list of enabled and disabled Windows Features on a Windows Client OS PC and toggles the state of the selected items so that enabled items become disabled and disabled items are enabled. It depends on DISM. You must run it as an administrator. .NOTES Alan Kaplan 5/20/2017 ver 1.1 9/16/2017 added echo of command to screen #> ## test for restart needed? function Test-IsAdmin { ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") } if (!(Test-IsAdmin)) { write-warning "Script requires admin privileges to run, quitting." pause Exit } #Map of Install states $Install = @{ 1 = "Enabled" 2 = "Disabled" 3 = "Absent" 4 = "Unknown" } #Get list of Windows features and install state from WMI, then send to Out-Gridview Get-wmiobject -query 'SELECT * FROM Win32_OptionalFeature ' | Sort-Object name | Select-Object @{ Name = "FeatureName" Expression ={ $_.name } }, @{ Name="Description" Expression = { $_.Caption } }, @{ Name="State" Expression = { $Install[[int]$_.InstallState] } } | Out-GridView -Title "Select Features to Enable/Disable" -OutputMode Multiple -OutVariable TaskList #Build and execute DISM command line to enable features $Features = $null if ($TaskList.count -eq 0) { Write-Warning "Nothing to do, quitting" Pause Exit } $EnableList = $TaskList | Where-Object -FilterScript { $_.State -eq "Disabled" } if ($EnableList.featurename.count -gt 0) { $EnableList| Foreach ` -Begin {$cmd = "DISM /Online /Enable-Feature"} ` -Process {$Features += " /FeatureName:$($_.FeatureName)"} ` -end { write-host "Running: $cmd $features /norestart" -ForegroundColor Green IEX "$cmd $features /norestart" } } #Build and execute DISM command line to disable features $Features=$null $DisableList = $TaskList | Where-Object -FilterScript { $_.State -eq "Enabled" } if ($DisableList.featurename.count -gt 0) { $DisableList| Foreach ` -Begin {$cmd = "DISM /Online /Disable-Feature"} ` -Process {$Features += " /FeatureName:$($_.FeatureName)"} ` -end { write-host "Running: $cmd $features /norestart" -ForegroundColor Green IEX "$cmd $features /norestart" } } Pause