Como posso instalar o .NET 4.5.2 via PowerShell DSC?

Como posso instalar o .NET 4.5.2 via PowerShell DSC?

Posso instalar o .NET Framework 4.5 no Windows Server 2012 R2 usando o PowerShell DSC por meio do recurso WindowsFeature e do recurso NET-Framework-45-Core. Minha pergunta é: como uso o PowerShell DSC para garantir que o .NET 4.5.2 esteja instalado?

Responder1

Não tenho certeza se isso ainda é exigido pelo OP, mas tive exatamente o mesmo desafio recentemente e encontrei muitos problemas com o próprio instalador, ao tentar usar apenas o recurso do pacote em um servidor 2012 R2. Acabei tendo que escrever um recurso de script e usar o instalador da web, pois o pacote completo não conseguia descompactar com um erro muito genérico.

De qualquer forma, aqui está um recurso de script funcional que encontrei:

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

Responder2

De acordo comeste artigo do Microsoft Technet, o nome do recurso a ser instalado deverá ser um dosGet-WindowsFeatureresultado do comando. Portanto, se o .NET 4.5.2 não aparecer na lista, você não poderá garantir que ele seja instalado via DSC.

NomeIndica o nome da função ou recurso que você deseja garantir que seja adicionado ou removido. É igual à propriedade Name do cmdlet Get-WindowsFeature e não ao nome de exibição da função ou recurso.

Então acho que você terá que instalar a versão principal via DCS (4.5) e então descobrir a melhor solução para atualizá-la para 4.5.2.

informação relacionada