
Ich kann .NET Framework 4.5 auf Windows Server 2012 R2 mithilfe von PowerShell DSC über die WindowsFeature-Ressource und die Funktion NET-Framework-45-Core installieren. Meine Frage ist: Wie stelle ich mithilfe von PowerShell DSC sicher, dass .NET 4.5.2 installiert ist?
Antwort1
Ich bin mir nicht sicher, ob dies vom OP noch verlangt wird, aber ich hatte kürzlich genau dasselbe Problem und fand viele Probleme mit dem Installationsprogramm selbst, als ich versuchte, nur die Paketressource auf einem 2012 R2-Server zu verwenden. Am Ende musste ich eine Skriptressource schreiben und das Webinstallationsprogramm verwenden, da das vollständige Paket immer wieder mit einem sehr allgemeinen Fehler nicht dekomprimiert werden konnte.
Wie dem auch sei, hier ist eine funktionierende Skriptressource, die ich am Ende hatte:
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
Antwort2
Entsprechenddieser Microsoft Technet-Artikel, der Name der zu installierenden Funktion sollte einer aus derGet-WindowsFeatureErgebnis des Befehls. Wenn .NET 4.5.2 nicht in der Liste erscheint, können Sie also nicht sicherstellen, dass es über DSC installiert wurde.
NameGibt den Namen der Rolle oder des Features an, das hinzugefügt oder entfernt werden soll. Dies entspricht der Eigenschaft „Name“ des Cmdlets „Get-WindowsFeature“ und nicht dem Anzeigenamen der Rolle oder des Features.
Ich schätze, Sie müssen die Hauptversion (4.5) über DCS installieren und dann die beste Lösung finden, um sie auf 4.5.2 zu aktualisieren.