I recently came across and issue in my organization that involved me enabling the .NET Framework 3.5 and 4.8 optional features for a user on Windows 10. The issue caused some of our in-house created software to crash and I was informed by my manager after resolving the issue that this user is not alone and he has had to help users with this same issue before.
I tasked myself with creating a Worklet that would check if these optional features are enabled on a Windows 10 machine, and if they are not, enable them! With the help of Ask Otto, this task was a breeze and dramatically cut down the time it took to create both of the scripts.
(Granted, a few tweaks did need to be made to the syntax of some commands but Ask Otto was able to make a pretty solid script with just a few detailed instructions).
If you notice something that could be improved or that could be changed to improve either script please let me know, I’m fairly green when it comes to creating scripts and I’m open to suggestions for improvement! :)
Evaluation Script:
# ======================
# Otto AI Generated Code
# ======================
# Check if .NET Framework 3.5 is enabled
$dotnet35Status = Get-WindowsOptionalFeature -Online -FeatureName "NetFx3"
$dotnet35Enabled = $dotnet35Status.State -eq "Enabled"
# Check if .NET Framework 4.8 is enabled
$dotnet48Status = Get-WindowsOptionalFeature -Online -FeatureName "NetFx4-AdvSrvs"
$dotnet48Enabled = $dotnet48Status.State -eq "Enabled"
# Enable .NET Framework 3.5 if it is disabled
if (-not $dotnet35Enabled) {
Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -NoRestart
if ($?) {
Write-Host ".NET Framework 3.5 has been enabled."
exit 0
} else {
Write-Host "Error occurred while enabling .NET Framework 3.5."
exit 1
}
}
# Enable .NET Framework 4.8 if it is disabled
if (-not $dotnet48Enabled) {
Enable-WindowsOptionalFeature -Online -FeatureName "NetFx4-AdvSrvs" -NoRestart
if ($?) {
Write-Host ".NET Framework 4.8 has been enabled."
exit 0
} else {
Write-Host "Error occurred while enabling .NET Framework 4.8."
exit 1
}
}
# Check if both frameworks are enabled
if ($dotnet35Enabled -and $dotnet48Enabled) {
Write-Host "Both .NET Framework 3.5 and 4.8 are enabled."
exit 0
} else {
Write-Host "Error occurred while enabling .NET Frameworks."
exit 1
}
Remediation Script:
# ======================
# Otto AI Generated Code
# ======================
# Check if .NET Framework 3.5 is enabled
$dotNet35Enabled = Get-WindowsOptionalFeature -Online -FeatureName NetFx3 | Select-Object -ExpandProperty State
# Check if .NET Framework 4.8 is enabled
$dotNet48Enabled = Get-WindowsOptionalFeature -Online -FeatureName NetFx4-AdvSrvs | Select-Object -ExpandProperty State
# Enable .NET Framework 3.5 if disabled
if ($dotNet35Enabled -ne 'Enabled') {
Enable-WindowsOptionalFeature -Online -FeatureName NetFx3 -All -NoRestart
}
# Enable .NET Framework 4.8 if disabled
if ($dotNet48Enabled -ne 'Enabled') {
Enable-WindowsOptionalFeature -Online -FeatureName NetFx4-AdvSrvs -All -NoRestart
}
# Check if both frameworks are enabled
$dotNet35Enabled = Get-WindowsOptionalFeature -Online -FeatureName NetFx3 | Select-Object -ExpandProperty State
$dotNet48Enabled = Get-WindowsOptionalFeature -Online -FeatureName NetFx4-AdvSrvs | Select-Object -ExpandProperty State
# Exit with appropriate exit code and message
if ($dotNet35Enabled -eq 'Enabled' -and $dotNet48Enabled -eq 'Enabled') {
Write-Host "Both .NET Framework 3.5 and 4.8 are enabled."
exit 0
} else {
Write-Host "Error: Failed to enable one or both .NET Framework versions."
exit 1
}