xInstallDotNet48Framework.psm1
[DscResource()] class InstallDotNet48 { #[string]$source = "http://download.microsoft.com/download/F/9/4/F942F07D-F26F-4F30-B4E3-EBD54FABA377/NDP462-KB3151800-x86-x64-AllOS-ENU.exe" [string]$source = "https://download.visualstudio.microsoft.com/download/pr/014120d7-d689-4305-befd-3cb711108212/0fd66638cde16859462a6243a4629a50/ndp48-x86-x64-allos-enu.exe" [DscProperty(Key)] [string]$dest [void] Set() { # Download Installer File if needed if(!$this.IsExecutableAvailable()) { $this.DownloadFile() } # Install DotNetFramework $proc = Start-Process -FilePath $this.dest -ArgumentList "/quiet /norestart /log C:\ndp48-x86-x64-allos-enu.exe_install.log" -PassThru -Wait # Cleanup Installer file if($this.IsExecutableAvailable()) { Remove-Item $this.dest } Switch($proc.ExitCode) { 0 { # Success } 1603 { Throw "Failed installation" } 1641 { # Restart required $global:DSCMachineStatus = 1 } 3010 { # Restart required $global:DSCMachineStatus = 1 } 5100 { Throw "Computer does not meet system requirements." } default { Throw "Unknown exit code $($proc.ExitCode)" } } } [bool] Test() { $dotNetFull = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | Get-ItemProperty -name Version,Release -EA 0 | Where { $_.Version -match '4.8.03761' -and $_.PSChildName -eq 'Full' } return !($dotNetFull -eq $null) } [InstallDotNet48] Get() { return $this } [bool] IsExecutableAvailable() { return Test-Path $this.dest } [void] DownloadFile() { Invoke-WebRequest $this.source -OutFile $this.dest } } |