Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

Mit dem Absenden dieses Formulars akzeptiere ich die Datenschutzerklärung von NinjaOne.

So installieren Sie .NET Framework 4 mit PowerShell

Da sich der IT-Betrieb ständig weiterentwickelt und immer komplizierter wird, hat sich die Automatisierung als Eckpfeiler etabliert. Die Bedeutung der Skripterstellung, insbesondere mit PowerShell, ist in modernen IT-Infrastrukturen nicht von der Hand zu weisen. PowerShell ist mit seiner Fähigkeit, Aufgaben zu automatisieren und zu rationalisieren, unverzichtbar geworden. Heute besprechen wir ein spezielles PowerShell-Skript zur Installation von .NET Framework 4, einer wichtigen Grundlage für viele Anwendungen.

Hintergrund

Das .NET Framework von Microsoft fungiert als Software-Entwicklungsplattform, die Dienste, Bibliotheken und Werkzeuge bereitstellt, die für die Entwicklung und Ausführung einer Vielzahl von Anwendungen erforderlich sind. Für IT-Fachleute und Managed Service Provider (MSPs) ist es von größter Bedeutung, über eine effiziente Methode zur Installation dieses Frameworks zu verfügen, um sicherzustellen, dass die Anwendungen reibungslos funktionieren. Unser PowerShell-Skript erfüllt diesen Zweck mit zusätzlichen Funktionen, wie z. B. der Möglichkeit, von einer Offline-Quelle zu installieren.

Das Skript

#Requires -Version 5.1

<#
.SYNOPSIS
    Install NetFx4 features(.NET 4.x), with the option to install from an offline source.
.DESCRIPTION
    Install NetFx4 features(.NET 4.x), with the option to install from an offline source.
    An offline source can be an attached CD/DVD image of the OS's installer.
.EXAMPLE
     No parameters needed.
    Install NetFx4 features from Local Install/Windows Update/WSUS.
.EXAMPLE
     -OfflineSource "D:sourcessxs"
    Install NetFx4 features from a specified source.
.EXAMPLE
    PS C:> Install-DotNet4.ps1
    Install NetFx4 features from Local Install/Windows Update/WSUS.
.EXAMPLE
    PS C:> Install-DotNet4.ps1 -OfflineSource "D:sourcessxs"
    Install NetFx4 features from a specified source.
.OUTPUTS
    None
.NOTES
    General notes
    Release Notes:
    Initial Release
By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#>

[CmdletBinding()]
param (
    [Parameter()]
    [String]
    $OfflineSource
)

begin {
    $OSVersion = [System.Environment]::OSVersion.Version
}
process {
    if ($OSVersion -gt [Version]::new(6, 2)) {
        # Windows 8.1/Server 2012 R2 or greater
        $Packages = dism /Online /Get-Features /Format:Table
        if ($OfflineSource) {
            # Install .NET 3 and 4
            if ((Test-Path -Path $OfflineSource -ErrorAction SilentlyContinue)) {
                if ($($Packages | Select-String -Pattern "NetFx4" | Select-Object -First 1) -like "Disabled") {
                    dism /Online /Enable-Feature /FeatureName:NetFx4 /All /Source:$OfflineSource
                }
            }
            else {
                Write-Error "Path to $OfflineSource doesn't exist."
            }
        }
        else {
            if ($($Packages | Select-String -Pattern "NetFx4" | Select-Object -First 1) -like "Disabled") {
                dism /Online /Enable-Feature /FeatureName:NetFx4 /All
            }
        }
    }
    else {
        # Windows 8/Server 2012 or lesser
        # This requires copying the installer to the target in some way; either by downloading or shared folder as examples.
        Write-Output "More Info: https://ninjarmm.zendesk.com/hc/en-us/articles/360043992771-How-to-install-software-outside-of-3rd-Party-Patching"
        Write-Error "Use the Install Application script to install dotNetFx40_Full_x86_x64.exe"

        # The code below is an example of downloading, but isn't guarantied to work 100%.

        # Invoke-WebRequest -Uri "http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe" -OutFile "dotNetFx40_Full_x86_x64.exe"
        # dotNetFx40_Full_x86_x64.exe /q: http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe
        # Remove-Item -Path "dotNetFx40_Full_x86_x64.exe"
    }
}
end {}

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

Detailansicht

Schauen wir uns nun die Kernkomponenten dieses Skripts an:

  • Parameter: Das Skript beginnt mit dem Einrichten eines Parameters $OfflineSource. Falls vorhanden, können Benutzer das Framework von einer anderen als der Standardquelle (z. B. einer lokalen Quelle) installieren.
  • Umgebungsprüfung: Es ruft die aktuelle Version des Betriebssystems ab
  • Prozess:
  • Wenn die Betriebssystemversion größer als Windows 8.1/Server 2012 R2 ist, wird nach verfügbaren Paketen gesucht.
  • Abhängig von der $OfflineSource wird entweder die lokale Quelle oder die Standardquelle für die Installation des Frameworks verwendet.
  • Für Betriebssystemversionen unter Windows 8/Server 2012 bietet das Skript einen Leitfaden für die Installation und schlägt eine manuelle Download-Methode vor.

Potenzielle Anwendungsfälle

Szenario: Stellen Sie sich James vor, einen IT-Administrator für ein mittelständisches Unternehmen. Das Unternehmen migriert einige ältere Anwendungen in eine neuere Umgebung und benötigt dafür .NET Framework 4 auf allen Servern. Einige Server haben einen eingeschränkten Online-Zugang, so dass eine Offline-Installation erforderlich ist. Mit diesem Skript kann James die Installation auf mehreren Servern optimieren, was Zeit spart und Einheitlichkeit gewährleistet.

Vergleiche

Die herkömmliche Installation von .NET Framework kann das manuelle Herunterladen des Installationsprogramms und das Durchlaufen des Setups oder die Verwendung der Windows-Funktionsinstallation umfassen. Unser Skript bietet Vorteile:

  • Automatisierung: Planen Sie die Bereitstellung auf mehreren Servern oder führen Sie sie sofort durch.
  • Flexibilität: Wählen Sie zwischen Online- und Offline-Installation
  • Fehler-Prüfungen:Bietet spezifisches Feedback, wenn etwas nicht wie geplant läuft.

FAQs

  • Kann ich dieses Skript auch für andere Versionen als .NET Framework 4 verwenden?
    Dieses Skript wurde speziell für .NET Framework 4 entwickelt. Für andere Versionen müssten Änderungen vorgenommen werden.
  • Wie kann ich sicherstellen, dass meine Offline-Quelle korrekt ist?
    Stellen Sie sicher, dass der unter $OfflineSource angegebene Pfad auf die richtigen Installationsdateien verweist.

Auswirkungen

Bei der Automatisierung von Installationen, insbesondere bei Skripten, die Systemeinstellungen ändern, besteht ein innewohnendes Risiko. Eine fehlerhafte Installation kann zu Schwachstellen im System führen. Es ist wichtig, das Skript gründlich zu verstehen und es vor dem breiten Einsatz in einer kontrollierten Umgebung zu testen.

Empfehlungen

  • Erstellen Sie immer eine Sicherungskopie Ihres Systems, bevor Sie Skripte ausführen, die Systemkonfigurationen ändern.
  • Wenn Sie eine Offline-Quelle verwenden, achten Sie darauf, dass sie von einem vertrauenswürdigen und seriösen Anbieter stammt.
  • Aktualisieren Sie das Skript regelmäßig, um es an neuere Betriebssystemversionen oder Updates für das .NET Framework anzupassen.

Abschließende Überlegungen

In der heutigen IT-Landschaft ist der Einsatz von Tools wie NinjaOne unerlässlich geworden. Wie wir bei diesem .NET-Installationsskript gesehen haben, kann die Automatisierung komplizierte Aufgaben vereinfachen. Die umfassende Plattform von NinjaOne kann bei der effektiven Bereitstellung und Verwaltung solcher Skripte helfen und so sicherstellen, dass der IT-Betrieb reibungslos und effizient bleibt.

Nächste Schritte

Der Aufbau eines effizienten und effektiven IT-Teams erfordert eine zentralisierte Lösung, die als vereintes Tool für die Bereitstellung von Dienstleistungen fungiert. NinjaOne ermöglicht es IT-Teams, all ihre Geräte zu überwachen, verwalten, sichern und zu unterstützen, unabhängig von ihrem Ort und komplexer Infrastruktur vor Ort.

Erfahren Sie mehr über NinjaOne Endpoint Management schauen Sie sich eine Live-Tour an oder starten Sie Ihre kostenlose Testversion der NinjaOne Plattform.

Kategorien:

Das könnte Sie auch interessieren

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).