-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptionalfeature.ps1
44 lines (29 loc) · 1.13 KB
/
optionalfeature.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Enable-OptionalFeature ($name){
foreach($entry in $input){
$feature=$entry.name
Dism /Online /Enable-Feature /FeatureName:$feature /NoRestart #/quiet
}
}
function Disable-OptionalFeature ([string]$name){
foreach($entry in $input){
$feature=$entry.name
Dism /Online /disable-Feature /FeatureName:$feature /NoRestart #/quiet
}
}
function Get-OptionalFeature {
$win32_optionalfeature_out=@()
$win32_optionalfeature= Get-WmiObject -query "select * from win32_optionalfeature "|Select-Object name,installstate
$win32_optionalfeature|ForEach-Object{
$state=$_.installstate
switch ($state)
{
1 {$state='Enabled'; Break}
2 {$state="Disabled" ; Break }
3 {$state="Absent" ; Break }
4 {$state="Unknown" ; Break }
}#end switch
$_.installstate=$state
$win32_optionalfeature_out+=$_
}
$win32_optionalfeature_out|Where-Object {$_.installstate -ne [int]}
}