User Tools

Site Tools


script:powershell:psdotnet

Powershell: Installer le module dotnet 3.5

Voici comment installer le module Dotnet 3.5 via un script powershell, il a été trouvé: ici, penser à remercier son auteur.

Function Install-OSCNetFx3 
{ 
<# 
     .SYNOPSIS 
        Install-OSCNetFx3 is an advanced function which can be used to install .NET Framework 3.5 in Windows 8. 
    .DESCRIPTION 
        Install-OSCNetFx3 is an advanced function which can be used to install .NET Framework 3.5 in Windows 8. 
    .PARAMETER  Online 
        It will download .NET Framework 3.5 online and install it. 
    .PARAMETER     LocalSource 
        The path of local source which includes .NET Framework 3.5 source. 
    .PARAMETER    TemplateID 
        The ID of the template in the template group 
    .EXAMPLE 
        C:\PS> Install-OSCNetFx3 -Online 
         
        This command shows how to download .NET Framework 3.5 online and install it. 
    .EXAMPLE 
        C:\PS> Install-OSCNetFx3 -LocalSource G:\sources\sxs 
         
        This command shows how to use local source to install .NET Framework 3.5. 
                 
#> 
    [CmdletBinding()] 
    Param 
    ( 
        [Parameter(Mandatory=$False,Position=0)][Switch]$Online, 
        [Parameter(Mandatory=$False,Position=0)][String]$LocalSource 
    ) 
    If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` 
    [Security.Principal.WindowsBuiltInRole] "Administrator")) 
    { 
        Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!" 
        Break 
    } 
    Else 
    { 
        $Caption = (Get-WmiObject "win32_operatingsystem" | Select caption).Caption 
 
        If($Caption -match "Microsoft Windows 8" -OR $Caption -match "Microsoft Windows 7" -OR $Caption -match "Microsoft Windows 10") 
        { 
            $Result = Dism /online /get-featureinfo /featurename:NetFx3 
            If($Result -contains "State : Enabled") 
            { 
                Write-Warning ".Net Framework 3.5 has been installed and enabled." 
            } 
            Else  
            { 
                if($LocalSource) 
                { 
                    Write-Host "Installing .Net Framework 3.5, do not close this prompt..." 
                    DISM /Online /Enable-Feature /FeatureName:NetFx3 /Source:$LocalSource | Out-Null  
                    $Result = Dism /online /Get-featureinfo /featurename:NetFx3 
                    If($Result -contains "State : Enabled") 
                    { 
                        Write-Host "Install .Net Framework 3.5 successfully." 
                    } 
                    Else 
                    { 
                        Write-Host "Failed to install Install .Net Framework 3.5,please make sure the local source is correct." 
                    } 
                } 
                Else  
                {     
                    Write-Host "Installing .Net Framework 3.5, do not close this prompt..." |  
                    Dism /online /Enable-feature /featurename:NetFx3 | Out-Null  
                    $Result = Dism /online /Get-featureinfo /featurename:NetFx3 
                    If($Result -contains "State : Enabled") 
                    { 
                        Write-Host "Install .Net Framework 3.5 successfully." 
                    } 
                    Else 
                    { 
                        Write-Host "Failed to install Install .Net Framework 3.5, you can use local source to try again." 
                    } 
                } 
            } 
        } 
        Else 
        { 
            Write-Error "Please run this script in Windows 10, Windows 8/8.1 or Windows 7" 
        } 
    } 
} 
 
Export-ModuleMember -Function "Install-OSCNetFx3"

script/powershell/psdotnet.txt · Last modified: 2020/08/10 23:07 (external edit)