Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

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

Wie man ISO-Dateien dynamisch mit PowerShell einbindet und ausbindet

In diesem Beitrag stellen wir ein PowerShell-Skript für IT-Administratoren bereit, mit dem sie ISO-Dateien dynamisch einbinden und ausbinden können.

Hintergrund

ISO-Dateien, im Wesentlichen eine vollständige Kopie einer Disc in digitaler Form, werden weit verbreitet zur Verteilung von Software verwendet (einschließlich leider auch Malware). IT-Profis und Managed Service Provider (MSPs) bevorzugen möglicherweise generell das Blockieren des Mountens von ISO-Dateien, oder sie könnten auf die Notwendigkeit  stoßen, das Mounten dieser ISO-Images dynamisch zu aktivieren oder zu deaktivieren, insbesondere in Unternehmenssystemen. Dieses PowerShell-Skript bietet eine präzise Steuerung dieser Funktion, um sicherzustellen, dass Sicherheits- und Richtlinienanforderungen auf elegante Weise erfüllt werden können.

Das Skript

#Requires -Version 5.1

<#
.SYNOPSIS
    Enables or disables the mounting of ISO images.
.DESCRIPTION
    Enables or disables the mounting of ISO images.
.EXAMPLE
     -Enable
    Enables mounting of ISO images.
.EXAMPLE
     -Disable
    Disables mounting of ISO images.
.OUTPUTS
    None
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    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()]
    [switch]
    $Enable,
    [Parameter()]
    [switch]
    $Disable
)

begin {
    function Set-ItemProp {
        param (
            $Path,
            $Name,
            $Value,
            [ValidateSet("DWord", "QWord", "String", "ExpandedString", "Binary", "MultiString", "Unknown")]
            $PropertyType = "DWord"
        )
        # Do not output errors and continue
        $ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
        if (-not $(Test-Path -Path $Path)) {
            # Check if path does not exist and create the path
            New-Item -Path $Path -Force | Out-Null
        }
        if ((Get-ItemProperty -Path $Path -Name $Name)) {
            # Update property and print out what it was changed from and changed to
            $CurrentValue = Get-ItemProperty -Path $Path -Name $Name
            try {
                Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false -ErrorAction Stop | Out-Null
            }
            catch {
                Write-Error $_
            }
            Write-Host "$Path$Name changed from $CurrentValue to $(Get-ItemProperty -Path $Path -Name $Name)"
        }
        else {
            # Create property with value
            try {
                New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false -ErrorAction Stop | Out-Null
            }
            catch {
                Write-Error $_
            }
            Write-Host "Set $Path$Name to $(Get-ItemProperty -Path $Path -Name $Name)"
        }
        $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Continue
    }
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }
}
process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }

    if ($env:Action -like "Enable") {
        $Enable = $true
    }
    elseif ($env:Action -like "Disable") {
        $Disable = $true
    }

    # Use a unique number that isn't likely to be used
    # "ninja" to something close to a number plus 1 at the end: "41470" + "1"
    $GroupName = "414701"

    # Mount HKEY_CLASSES_ROOT as HKCR: for the current session
    New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR

    if ($Enable -and $Disable) {
        Write-Error "Both Enable and Disable can not be used at the same time."
        exit 1
    }
    elseif ($Enable) {
        # Enables the use of ISO mounting by removing registry settings

        # ErrorAction set to SilentlyContinue for when the registry settings don't exist
        Remove-ItemProperty -Path "HKLM:SOFTWAREPoliciesMicrosoftWindowsDeviceInstallRestrictionsDenyDeviceIDs" -Name "$GroupName" -ErrorAction SilentlyContinue
        Write-Host "Removed $GroupName from HKLM:SOFTWAREPoliciesMicrosoftWindowsDeviceInstallRestrictionsDenyDeviceIDs"

        Remove-ItemProperty -Path "HKLM:SOFTWAREPoliciesMicrosoftWindowsDeviceInstallRestrictions" -Name "DenyDeviceIDsRetroactive" -ErrorAction SilentlyContinue
        Write-Host "Removed DenyDeviceIDsRetroactive from HKLM:SOFTWAREPoliciesMicrosoftWindowsDeviceInstallRestrictionsDenyDeviceIDs"

        Remove-ItemProperty -Path "HKCR:Windows.IsoFileshellmount" -Name "ProgrammaticAccessOnly" -ErrorAction SilentlyContinue
        Write-Host "Removed ProgrammaticAccessOnly from HKCR:Windows.IsoFileshellmount"
    }
    elseif ($Disable) {
        # Disables the use of ISO mounting by creating registry settings

        Set-ItemProp -Path "HKLM:SOFTWAREPoliciesMicrosoftWindowsDeviceInstallRestrictionsDenyDeviceIDs" -Name "$GroupName" -Value "SCSICdRomMsft____Virtual_DVD-ROM_" -PropertyType String
        Set-ItemProp -Path "HKLM:SOFTWAREPoliciesMicrosoftWindowsDeviceInstallRestrictions" -Name "DenyDeviceIDsRetroactive" -Value "1" -PropertyType DWord
        Set-ItemProp -Path "HKCR:Windows.IsoFileshellmount" -Name "ProgrammaticAccessOnly" -Value "" -PropertyType String
    }
    else {
        Write-Error "Enable or Disable is required."
        exit 1
    }
    Write-Host "Any logged in users will need to log out and back in for changes to take effect."
}
end {
    $ScriptVariables = @(
        [PSCustomObject]@{
            name           = "Action"
            calculatedName = "action"
            required       = $true
            defaultValue   = [PSCustomObject]@{
                type  = "TEXT"
                value = "Disable"
            }
            valueType      = "DROPDOWN"
            valueList      = @(
                [PSCustomObject]@{
                    type  = "UNDEFINED"
                    value = "Disable"
                },
                [PSCustomObject]@{
                    type  = "UNDEFINED"
                    value = "Enable"
                }
            )
            description    = "Used to enable or disable the mounting of ISO images."
        }
    )
}

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

Detailansicht

Das bereitgestellte Skript ist darauf ausgelegt, die Montagefähigkeit von ISO-Images umzuschalten. Lassen Sie uns seine Bestandteile analysieren:

  • Parameter: Das Skript akzeptiert zwei Schalter – $Enable und $Disable. Sie bestimmen das Verhalten des Skripts und aktivieren oder deaktivieren die ISO-Einbindung.
  • Set-ItemProp Funktion: Diese interne Funktion dient der Erstellung oder Änderung einer Registrierungseigenschaft. Es ist für verschiedene Eigenschaftstypen geeignet und gewährleistet Flexibilität bei der Verwaltung von Windows-Registrierungsschlüsseln.
  • Test-IsElevated-Funktion: Überprüft, ob das Skript mit administrativen Rechten läuft. Dadurch wird sichergestellt, dass Änderungen systemweit und nicht nur in der Sitzung des Benutzers vorgenommen werden.
  • Prozess-Block: Der Kern des Skripts. Hier liegt die Logik:
  • Überprüft die administrativen Rechte.
  • Bestimmt die Aktion anhand der angegebenen Parameter oder Umgebungsvariablen.
  • Entfernt (Aktivierung) oder setzt (Deaktivierung) bestimmte Registrierungsschlüssel zur Steuerung der ISO-Montagefähigkeit.

Potenzielle Anwendungsfälle

Betrachten Sie eine Fallstudie: Die IT-Abteilung der Acme Corp. verteilt ein Software-Update über ISO-Dateien an alle Mitarbeitersysteme. Sobald die Aktualisierung abgeschlossen ist, soll die ISO-Montagefunktion vorübergehend deaktiviert werden. Indem sie dieses Skript im gesamten Unternehmen bereitstellen, können sie diese Funktionalität steuern und sicherstellen, dass inoffizielle oder nicht genehmigte ISOs nicht von neugierigen Benutzern gemountet werden.

Vergleiche

Obwohl manuelle Eingriffe oder GUI-basierte Tools die Berechtigungen für das Mounten von ISOs verwalten können, sind sie für groß angelegte Operationen ineffizient. Unser Skript bietet eine automatisierte, mühelose und robuste Methode im Vergleich zu zeitaufwändigen manuellen Prozessen.

FAQs

  • Benötigt das Skript Admin-Rechte?
    Ja, für systemweite Änderungen muss das Skript mit Administratorrechten ausgeführt werden.
  • Kann ich gleichzeitig aktivieren und deaktivieren?
    Nein. Das Skript erfordert eine bestimmte Aktion, entweder die Aktivierung oder die Deaktivierung.

Auswirkungen

Die Verwaltung der Fähigkeit, ISO-Dateien zu mounten, kann tiefgreifende Auswirkungen auf die Sicherheit haben. Nicht autorisierte ISOs können Malware oder unerwünschte Software einführen. Durch die Kontrolle dieser Funktion können IT-Abteilungen sicherstellen, dass nur genehmigte ISOs aufgespielt werden, wodurch potenzielle Bedrohungen eingedämmt werden.

Empfehlungen

  • Sichern Sie immer die Registrierungseinstellungen, bevor Sie Änderungen vornehmen.
  • Testen Sie das Skript vor dem unternehmensweiten Einsatz in einer kontrollierten Umgebung.
  • Überwachen Sie das Systemverhalten nach der Bereitstellung, um unerwartete Ergebnisse zu ermitteln.

Abschließende Überlegungen

Für Plattformen wie NinjaOne, die sich an IT-Betrieb und -Verwaltung richten, sind Skripte wie diese von unschätzbarem Wert. Sie zeigen die Vielseitigkeit der Plattform und ihre Anpassung an die heutigen IT-Anforderungen. Durch den Einsatz solcher Tools können IT-Experten die volle Leistungsfähigkeit von PowerShell nutzen und die Systemverwaltung effizient und sicher gestalten.

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).