Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit 2f391ca

Browse files
committed
Change method of installing capabilities and optional features
- Adds compatibility with 2004 - Adds compatibility with "N" editions
1 parent 5036244 commit 2f391ca

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

Win10.psm1

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,12 +1105,14 @@ Function EnableConnectionSharing {
11051105
Function DisableRemoteAssistance {
11061106
Write-Output "Disabling Remote Assistance..."
11071107
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Remote Assistance" -Name "fAllowToGetHelp" -Type DWord -Value 0
1108+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "App.Support.QuickAssist*" } | Remove-WindowsCapability -Online | Out-Null
11081109
}
11091110

11101111
# Enable Remote Assistance - Not applicable to Server (unless Remote Assistance is explicitly installed)
11111112
Function EnableRemoteAssistance {
11121113
Write-Output "Enabling Remote Assistance..."
11131114
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Remote Assistance" -Name "fAllowToGetHelp" -Type DWord -Value 1
1115+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "App.Support.QuickAssist*" } | Add-WindowsCapability -Online | Out-Null
11141116
}
11151117

11161118
# Enable Remote Desktop
@@ -3300,46 +3302,50 @@ Function DisableDeveloperMode {
33003302
# Uninstall Windows Media Player
33013303
Function UninstallMediaPlayer {
33023304
Write-Output "Uninstalling Windows Media Player..."
3303-
Disable-WindowsOptionalFeature -Online -FeatureName "WindowsMediaPlayer" -NoRestart -WarningAction SilentlyContinue | Out-Null
3305+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "WindowsMediaPlayer" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
3306+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Media.WindowsMediaPlayer*" } | Remove-WindowsCapability -Online | Out-Null
33043307
}
33053308

33063309
# Install Windows Media Player
33073310
Function InstallMediaPlayer {
33083311
Write-Output "Installing Windows Media Player..."
3309-
Enable-WindowsOptionalFeature -Online -FeatureName "WindowsMediaPlayer" -NoRestart -WarningAction SilentlyContinue | Out-Null
3312+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "WindowsMediaPlayer" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
3313+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Media.WindowsMediaPlayer*" } | Add-WindowsCapability -Online | Out-Null
33103314
}
33113315

33123316
# Uninstall Internet Explorer
33133317
Function UninstallInternetExplorer {
33143318
Write-Output "Uninstalling Internet Explorer..."
3315-
Disable-WindowsOptionalFeature -Online -FeatureName "Internet-Explorer-Optional-$env:PROCESSOR_ARCHITECTURE" -NoRestart -WarningAction SilentlyContinue | Out-Null
3319+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -like "Internet-Explorer-Optional*" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
3320+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Browser.InternetExplorer*" } | Remove-WindowsCapability -Online | Out-Null
33163321
}
33173322

33183323
# Install Internet Explorer
33193324
Function InstallInternetExplorer {
33203325
Write-Output "Installing Internet Explorer..."
3321-
Enable-WindowsOptionalFeature -Online -FeatureName "Internet-Explorer-Optional-$env:PROCESSOR_ARCHITECTURE" -NoRestart -WarningAction SilentlyContinue | Out-Null
3326+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -like "Internet-Explorer-Optional*" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
3327+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Browser.InternetExplorer*" } | Add-WindowsCapability -Online | Out-Null
33223328
}
33233329

33243330
# Uninstall Work Folders Client - Not applicable to Server
33253331
Function UninstallWorkFolders {
33263332
Write-Output "Uninstalling Work Folders Client..."
3327-
Disable-WindowsOptionalFeature -Online -FeatureName "WorkFolders-Client" -NoRestart -WarningAction SilentlyContinue | Out-Null
3333+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "WorkFolders-Client" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33283334
}
33293335

33303336
# Install Work Folders Client - Not applicable to Server
33313337
Function InstallWorkFolders {
33323338
Write-Output "Installing Work Folders Client..."
3333-
Enable-WindowsOptionalFeature -Online -FeatureName "WorkFolders-Client" -NoRestart -WarningAction SilentlyContinue | Out-Null
3339+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "WorkFolders-Client" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33343340
}
33353341

3336-
# Uninstall PowerShell 2.0 Environment.
3342+
# Uninstall PowerShell 2.0 Environment
33373343
# PowerShell 2.0 is deprecated since September 2018. This doesn't affect PowerShell 5 or newer which is the default PowerShell environment.
33383344
# May affect Microsoft Diagnostic Tool and possibly other scripts. See https://blogs.msdn.microsoft.com/powershell/2017/08/24/windows-powershell-2-0-deprecation/
33393345
Function UninstallPowerShellV2 {
33403346
Write-Output "Uninstalling PowerShell 2.0 Environment..."
33413347
If ((Get-CimInstance -Class "Win32_OperatingSystem").ProductType -eq 1) {
3342-
Disable-WindowsOptionalFeature -Online -FeatureName "MicrosoftWindowsPowerShellV2Root" -NoRestart -WarningAction SilentlyContinue | Out-Null
3348+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "MicrosoftWindowsPowerShellV2Root" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33433349
} Else {
33443350
Uninstall-WindowsFeature -Name "PowerShell-V2" -WarningAction SilentlyContinue | Out-Null
33453351
}
@@ -3349,7 +3355,7 @@ Function UninstallPowerShellV2 {
33493355
Function InstallPowerShellV2 {
33503356
Write-Output "Installing PowerShell 2.0 Environment..."
33513357
If ((Get-CimInstance -Class "Win32_OperatingSystem").ProductType -eq 1) {
3352-
Enable-WindowsOptionalFeature -Online -FeatureName "MicrosoftWindowsPowerShellV2Root" -NoRestart -WarningAction SilentlyContinue | Out-Null
3358+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "MicrosoftWindowsPowerShellV2Root" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33533359
} Else {
33543360
Install-WindowsFeature -Name "PowerShell-V2" -WarningAction SilentlyContinue | Out-Null
33553361
}
@@ -3360,20 +3366,20 @@ Function InstallPowerShellV2 {
33603366
# For automated Linux distribution installation, see https://docs.microsoft.com/en-us/windows/wsl/install-on-server
33613367
Function InstallLinuxSubsystem {
33623368
Write-Output "Installing Linux Subsystem..."
3363-
Enable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" -NoRestart -WarningAction SilentlyContinue | Out-Null
3369+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Microsoft-Windows-Subsystem-Linux" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33643370
}
33653371

33663372
# Uninstall Linux Subsystem - Applicable since Win10 1607 and Server 1709
33673373
Function UninstallLinuxSubsystem {
33683374
Write-Output "Uninstalling Linux Subsystem..."
3369-
Disable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" -NoRestart -WarningAction SilentlyContinue | Out-Null
3375+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Microsoft-Windows-Subsystem-Linux" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33703376
}
33713377

33723378
# Install Hyper-V - Not applicable to Home
33733379
Function InstallHyperV {
33743380
Write-Output "Installing Hyper-V..."
33753381
If ((Get-CimInstance -Class "Win32_OperatingSystem").ProductType -eq 1) {
3376-
Enable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Hyper-V-All" -NoRestart -WarningAction SilentlyContinue | Out-Null
3382+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Microsoft-Hyper-V-All" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33773383
} Else {
33783384
Install-WindowsFeature -Name "Hyper-V" -IncludeManagementTools -WarningAction SilentlyContinue | Out-Null
33793385
}
@@ -3383,7 +3389,7 @@ Function InstallHyperV {
33833389
Function UninstallHyperV {
33843390
Write-Output "Uninstalling Hyper-V..."
33853391
If ((Get-CimInstance -Class "Win32_OperatingSystem").ProductType -eq 1) {
3386-
Disable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Hyper-V-All" -NoRestart -WarningAction SilentlyContinue | Out-Null
3392+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Microsoft-Hyper-V-All" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
33873393
} Else {
33883394
Uninstall-WindowsFeature -Name "Hyper-V" -IncludeManagementTools -WarningAction SilentlyContinue | Out-Null
33893395
}
@@ -3395,7 +3401,7 @@ Function UninstallSSHClient {
33953401
Get-WindowsCapability -Online | Where-Object { $_.Name -like "OpenSSH.Client*" } | Remove-WindowsCapability -Online | Out-Null
33963402
}
33973403

3398-
# Install OpenSSH Client
3404+
# Install OpenSSH Client - Applicable since 1803
33993405
Function InstallSSHClient {
34003406
Write-Output "Installing OpenSSH Client..."
34013407
Get-WindowsCapability -Online | Where-Object { $_.Name -like "OpenSSH.Client*" } | Add-WindowsCapability -Online | Out-Null
@@ -3409,7 +3415,7 @@ Function InstallSSHServer {
34093415
Start-Service "sshd" -WarningAction SilentlyContinue
34103416
}
34113417

3412-
# Uninstall OpenSSH Server
3418+
# Uninstall OpenSSH Server - Applicable since 1809
34133419
Function UninstallSSHServer {
34143420
Write-Output "Uninstalling OpenSSH Server..."
34153421
Stop-Service "sshd" -WarningAction SilentlyContinue
@@ -3420,7 +3426,7 @@ Function UninstallSSHServer {
34203426
Function InstallNET23 {
34213427
Write-Output "Installing .NET Framework 2.0, 3.0 and 3.5 runtimes..."
34223428
If ((Get-CimInstance -Class "Win32_OperatingSystem").ProductType -eq 1) {
3423-
Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -NoRestart -WarningAction SilentlyContinue | Out-Null
3429+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "NetFx3" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
34243430
} Else {
34253431
Install-WindowsFeature -Name "NET-Framework-Core" -WarningAction SilentlyContinue | Out-Null
34263432
}
@@ -3430,7 +3436,7 @@ Function InstallNET23 {
34303436
Function UninstallNET23 {
34313437
Write-Output "Uninstalling .NET Framework 2.0, 3.0 and 3.5 runtimes..."
34323438
If ((Get-CimInstance -Class "Win32_OperatingSystem").ProductType -eq 1) {
3433-
Disable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -NoRestart -WarningAction SilentlyContinue | Out-Null
3439+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "NetFx3" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
34343440
} Else {
34353441
Uninstall-WindowsFeature -Name "NET-Framework-Core" -WarningAction SilentlyContinue | Out-Null
34363442
}
@@ -3490,25 +3496,25 @@ Function RemovePhotoViewerOpenWith {
34903496
# Uninstall Microsoft Print to PDF
34913497
Function UninstallPDFPrinter {
34923498
Write-Output "Uninstalling Microsoft Print to PDF..."
3493-
Disable-WindowsOptionalFeature -Online -FeatureName "Printing-PrintToPDFServices-Features" -NoRestart -WarningAction SilentlyContinue | Out-Null
3499+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Printing-PrintToPDFServices-Features" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
34943500
}
34953501

34963502
# Install Microsoft Print to PDF
34973503
Function InstallPDFPrinter {
34983504
Write-Output "Installing Microsoft Print to PDF..."
3499-
Enable-WindowsOptionalFeature -Online -FeatureName "Printing-PrintToPDFServices-Features" -NoRestart -WarningAction SilentlyContinue | Out-Null
3505+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Printing-PrintToPDFServices-Features" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
35003506
}
35013507

35023508
# Uninstall Microsoft XPS Document Writer
35033509
Function UninstallXPSPrinter {
35043510
Write-Output "Uninstalling Microsoft XPS Document Writer..."
3505-
Disable-WindowsOptionalFeature -Online -FeatureName "Printing-XPSServices-Features" -NoRestart -WarningAction SilentlyContinue | Out-Null
3511+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Printing-XPSServices-Features" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
35063512
}
35073513

35083514
# Install Microsoft XPS Document Writer
35093515
Function InstallXPSPrinter {
35103516
Write-Output "Installing Microsoft XPS Document Writer..."
3511-
Enable-WindowsOptionalFeature -Online -FeatureName "Printing-XPSServices-Features" -NoRestart -WarningAction SilentlyContinue | Out-Null
3517+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Printing-XPSServices-Features" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
35123518
}
35133519

35143520
# Remove Default Fax Printer
@@ -3526,21 +3532,15 @@ Function AddFaxPrinter {
35263532
# Uninstall Windows Fax and Scan Services - Not applicable to Server
35273533
Function UninstallFaxAndScan {
35283534
Write-Output "Uninstalling Windows Fax and Scan Services..."
3529-
If ([System.Environment]::OSVersion.Version.Build -ge 19041) {
3530-
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Print.Fax.Scan*" } | Remove-WindowsCapability -Online | Out-Null
3531-
} Else {
3532-
Disable-WindowsOptionalFeature -Online -FeatureName "FaxServicesClientPackage" -NoRestart -WarningAction SilentlyContinue | Out-Null
3533-
}
3535+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "FaxServicesClientPackage" } | Disable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
3536+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Print.Fax.Scan*" } | Remove-WindowsCapability -Online | Out-Null
35343537
}
35353538

35363539
# Install Windows Fax and Scan Services - Not applicable to Server
35373540
Function InstallFaxAndScan {
35383541
Write-Output "Installing Windows Fax and Scan Services..."
3539-
If ([System.Environment]::OSVersion.Version.Build -ge 19041) {
3540-
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Print.Fax.Scan*" } | Add-WindowsCapability -Online | Out-Null
3541-
} Else {
3542-
Enable-WindowsOptionalFeature -Online -FeatureName "FaxServicesClientPackage" -NoRestart -WarningAction SilentlyContinue | Out-Null
3543-
}
3542+
Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "FaxServicesClientPackage" } | Enable-WindowsOptionalFeature -Online -NoRestart -WarningAction SilentlyContinue | Out-Null
3543+
Get-WindowsCapability -Online | Where-Object { $_.Name -like "Print.Fax.Scan*" } | Add-WindowsCapability -Online | Out-Null
35443544
}
35453545

35463546
##########

0 commit comments

Comments
 (0)