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!

Install-WindowsFeature -name NET-Framework-Core

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

Get-WindowsFeature -name NET-Framework-Core  

And finally, you can remove the feature easily enough

Remove-WindowsFeature -name NET-Framework-Core

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.

$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"
	write-host ".Net 3.5 is not installed. Installing..."
	Install-WindowsFeature -name NET-Framework-Core

Far quicker and simpler than going through the UI.

Author: Richie Lee

Full time computer guy, part time runner. Full time Dad, part time blogger. Knows a thing or two about Pokémon. Knows too much about SQL Agent. Writer of fractured sentences. Maker of the best damn macaroni cheese you've ever tasted.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s