Install .Net using PowerShell

I was installing SQL Server 2014 on an Azure server the other day when I remembered that I had not installed the .NET Framework 3.5. Going through the UI is always a pain, so I wondered if it is possible to install using PowerShell… well, I knew it would be, I just wondered how straight forward it would be. Turns out it’s very straightforward!

[code language=”powershell”]
Install-WindowsFeature -name NET-Framework-Core
[/code]

It’s also possible to check the whether .NET is installed or not.

[code language=”powershell”]
Get-WindowsFeature -name NET-Framework-Core
[/code]

And finally, you can remove the feature easily enough

[code language=”powershell”]
Remove-WindowsFeature -name NET-Framework-Core
[/code]

And because I like to automate tedious tasks, I created a PowerShell script to check and install .NET if it is not installed, or just ignore it if it is already installed. I know the script uses write-host to write the output directly to the console, and I should use write-output, but I like write-host because reasons.

[code language=”powershell”]
$b = Get-WindowsFeature -name NET-Framework-Core | Format-Table Installed -HideTableHeaders | Out-String
$b = $b.Trim()
if ($b -eq “True”)
{
write-host “.Net 3.5 is already installed”
}
else
{
write-host “.Net 3.5 is not installed. Installing…”
Install-WindowsFeature -name NET-Framework-Core
}
[/code]

Far quicker and simpler than going through the UI.

Leave a Reply

Your email address will not be published. Required fields are marked *