Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Install .NET 4.5.2

Posted on September 30, 2016 By David Kittell
Configuration Net452Install
{
    node "localhost"
    {

        LocalConfigurationManager
        {
            RebootNodeIfNeeded = $true
        }

        Script Install_Net_4.5.2
        {
            SetScript = {
                $SourceURI = "https://download.microsoft.com/download/B/4/1/B4119C11-0423-477B-80EE-7A474314B347/NDP452-KB2901954-Web.exe"
                $FileName = $SourceURI.Split('/')[-1]
                $BinPath = Join-Path $env:SystemRoot -ChildPath "Temp\$FileName"

                if (!(Test-Path $BinPath))
                {
                    Invoke-Webrequest -Uri $SourceURI -OutFile $BinPath
                }

                write-verbose "Installing .Net 4.5.2 from $BinPath"
                write-verbose "Executing $binpath /q /norestart"
                Sleep 5
                Start-Process -FilePath $BinPath -ArgumentList "/q /norestart" -Wait -NoNewWindow            
                Sleep 5
                Write-Verbose "Setting DSCMachineStatus to reboot server after DSC run is completed"
                $global:DSCMachineStatus = 1
            }

            TestScript = {
                [int]$NetBuildVersion = 379893

                if (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' | %{$_ -match 'Release'})
                {
                    [int]$CurrentRelease = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Release
                    if ($CurrentRelease -lt $NetBuildVersion)
                    {
                        Write-Verbose "Current .Net build version is less than 4.5.2 ($CurrentRelease)"
                        return $false
                    }
                    else
                    {
                        Write-Verbose "Current .Net build version is the same as or higher than 4.5.2 ($CurrentRelease)"
                        return $true
                    }
                }
                else
                {
                    Write-Verbose ".Net build version not recognised"
                    return $false
                }
            }

            GetScript = {
                if (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' | %{$_ -match 'Release'})
                {
                    $NetBuildVersion =  (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Release
                    return $NetBuildVersion
                }
                else
                {
                    Write-Verbose ".Net build version not recognised"
                    return ".Net 4.5.2 not found"
                }
            }
        }
    }
}

Net452Install -OutputPath $env:SystemDrive:\DSCconfig
Set-DscLocalConfigurationManager -ComputerName localhost -Path $env:SystemDrive\DSCconfig -Verbose
Start-DscConfiguration -ComputerName localhost -Path $env:SystemDrive:\DSCconfig -Verbose -Wait -Force

Reference: http://superuser.com/questions/920850/how-can-i-install-net-4-5-2-via-powershell-dsc

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell Windows

Post navigation

Previous post
Next post

Related Posts

Bash – Rename Picture

Posted on November 15, 2022August 17, 2024

for f in *.HEIC; do mv -v "$f" "${f%.HEIC}.heic" done # 1 set -eu -o pipefail # 2 count=$(find . -depth 1 -name "*.heic" | wc -l | sed ‘s/[[:space:]]*//’) echo "converting $count files .heic files to .jpg" # 3 magick mogrify -monitor -format jpg *.heic # 4 echo "Remove…

Read More

PHP WordPress – Check If MultiSite From CLI

Posted on November 3, 2015

require(dirname(__DIR__) . ‘/html/wp-config.php’); if(defined(‘WP_ALLOW_MULTISITE’)) { if (constant("WP_ALLOW_MULTISITE") == true) { echo "\nThis site is MultiSite\n"; } else { echo "\nThis site is not MultiSite\n"; } } else { echo "\nThis site is not MultiSite\n"; } All information on this site is shared with the intention to help. Before any source…

Read More

Delete Ektron User

Posted on July 29, 2013October 26, 2015

In order to force a deletion from the Ektron user list you must follow the below path. DISCLAIMER: This will remove all content that was ever created/touched by the user. –Permissions Table DELETE permissions_tbl FROM permissions_tbl INNER JOIN users ON permissions_tbl.user_id = users.user_id WHERE users.user_name = ‘dkittell’ –Group Table DELETE…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
  • Mac OS X Terminal - Parallels - Reset Windows User Password
  • PowerShell - IPv4 Range

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
  • Mac OS X Terminal - Parallels - Reset Windows User Password
  • PowerShell - IPv4 Range
©2025 David Kittell | WordPress Theme by SuperbThemes