How to Install .NET Framework 4.0 via Command Line or PowerShell on Windows Server 2008 R2


3 views

Before proceeding, ensure you have:

1. Windows Server 2008 R2 SP1 installed

2. Administrator privileges

3. Internet connection or offline installer available

For environments without internet access, download the offline installer first.

dism.exe /online /enable-feature /featurename:NetFx4 /all /Source:D:\sources\sxs /LimitAccess

Where /Source: points to your installation media or downloaded files.

For servers with internet access, use this PowerShell script:

$source = "http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe"
$destination = "$env:TEMP\dotnetfx40.exe"

Invoke-WebRequest -Uri $source -OutFile $destination
Start-Process -FilePath $destination -ArgumentList "/quiet /norestart" -Wait
Remove-Item $destination

After installation, verify using PowerShell:

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' -Recurse |
Get-ItemProperty -Name Version -EA 0 |
Where { $_.PSChildName -match 'Full' } |
Select PSChildName, Version

Error 0x800f0906: Typically appears when Windows Update services are blocked. Solution:

net stop wuauserv
net start wuauserv

Pending Reboot: If system requires reboot after installation, check status:

Test-PendingReboot -ComputerName localhost

For automation scripts, these additional switches are useful:

  • /q - Quiet mode
  • /norestart - Suppresses reboot
  • /log - Specify log file location

Before proceeding, ensure your Windows Server 2008 R2 meets these requirements:

  • Minimum 850MB free disk space
  • Administrator privileges
  • Windows Installer 3.1 or later
  • Internet connection for downloading binaries

Unlike .NET 3.5, .NET 4.0 isn't available as a Windows feature. You'll need to download the installer first:

# Download .NET 4.0 Full installer
$url = "https://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe"
$output = "$env:TEMP\dotNetFx40_Full_x86_x64.exe"
Invoke-WebRequest -Uri $url -OutFile $output

# Silent installation
Start-Process -FilePath $output -ArgumentList "/q /norestart" -Wait

For automated environments, WebPI provides a command-line interface:

# Download WebPI command line
$webPiUrl = "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi"
$webPiPath = "$env:TEMP\WebPI.msi"

# Install WebPI silently
msiexec /i $webPiPath /qn

# Install .NET 4.0 via WebPI
WebpiCmd.exe /Install /Products:NetFramework4 /AcceptEula
# Verify .NET 4.0 installation
Get-ChildItem "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\" | 
Where-Object { $_.PSChildName -match "Full" } | 
Select-Object PSChildName, Version

Expected output should show version 4.0.30319 or higher.

If you encounter errors, try these solutions:

  • Error 0x80070643: Run the installer with admin privileges
  • Pending reboot: Check registry: Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending"
  • Corrupt download: Verify file hash: Get-FileHash $output -Algorithm SHA256

For fully automated deployments, combine download and installation:

function Install-DotNet40 {
    param(
        [string]$DownloadPath = "$env:TEMP"
    )
    
    $url = "https://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe"
    $output = Join-Path -Path $DownloadPath -ChildPath "dotNetFx40_Full_x86_x64.exe"
    
    try {
        # Download
        Invoke-WebRequest -Uri $url -OutFile $output -ErrorAction Stop
        
        # Install
        $process = Start-Process -FilePath $output -ArgumentList "/q /norestart" -PassThru -Wait
        if ($process.ExitCode -ne 0) {
            throw "Installation failed with exit code $($process.ExitCode)"
        }
        
        return $true
    }
    catch {
        Write-Error "Failed to install .NET 4.0: $_"
        return $false
    }
}

# Usage
Install-DotNet40