Die wichtigsten Erkenntnisse
- Automatisiert Geräteberechtigungen: Das Skript vereinfacht das Festlegen von Berechtigungen auf Wechseldatenträgern.
- Unterstützt mehrere Geräte: Es deckt eine Reihe von Geräten ab, darunter USB, DVD, Diskettenlaufwerke, Bandlaufwerke und WPD.
- Erfordert Administratorrechte: Für die Ausführung des Skripts sind Administratorrechte erforderlich.
- Ändert die Einstellungen in der Registrierung: Das Skript passt die Berechtigungen an, indem er bestimmte Registrierungsschlüssel und -werte ändert.
- Gewährleistet Compliance und Sicherheit: Ideal für Umgebungen, in denen Datensicherheit und Compliance entscheidend sind.
- Flexible Kontrolle: Bietet die Möglichkeit, Lese-, Schreib- und Ausführungsaktionen sowohl zu verweigern als auch zu erlauben.
- Aktualisierung der Gruppenrichtlinien und Neustart: Schließt mit einer Aktualisierung der Gruppenrichtlinien und einem optionalen Neustart des Systems ab.
- Gefahr der Überbeschränkung: Es besteht die Gefahr, dass Arbeitsabläufe behindert werden, wenn zu restriktive Richtlinien angewendet werden.
- NinjaOne-Integration: Das Skript ergänzt Plattformen wie NinjaOne für ein breiteres IT-Management und Sicherheit.
Die Verwaltung des Zugriffs auf Wechseldatenträger ist ein wichtiger Aspekt der IT-Sicherheit. Diese Verantwortung ist besonders ausgeprägt in Umgebungen, in denen Datensicherheit und -integrität an erster Stelle stehen. PowerShell-Skripte wie das thematisierte bieten eine robuste Lösung für die effiziente Steuerung dieser Berechtigungen.
Kontext
Das vorgestellte Skript dient dazu, den Lese-, Schreib- und Ausführungszugriff auf verschiedene Wechseldatenträger wie Diskettenlaufwerke, CD/DVD-Laufwerke, Bandlaufwerke, Windows Portable Devices (WPD) und USB-Laufwerke zu aktivieren oder zu deaktivieren. Diese Funktionalität ist für IT-Expert:innen und Managed Service Provider (MSPs) unerlässlich, die Datensicherheitsrichtlinien durchsetzen, Datenlecks verhindern oder gesetzliche Vorschriften einhalten müssen.
Das Skript zur Verwaltung der Berechtigungen für Wechseldatenträger
#Requires -Version 2.0 <# .SYNOPSIS Disable or Enable Write, Read, and Execute access to Removable Storage devices. .DESCRIPTION Disable or Enable Write, Read, and Execute access to Floppy, CD/DVD, Tape, WPD, and/or USB. Disable actions are does first, then allow actions are done after. .EXAMPLE -Device DVD -DenyRead -DenyWrite -DenyExecute Disable Write, Read, and Execute access to CD/DVD drive. .EXAMPLE -Device DVD -AllowRead -AllowWrite -AllowExecute Allow Write, Read, and Execute access to CD/DVD drive. .EXAMPLE -Device DVD -DenyWrite -DenyExecute -AllowRead Disable Write, Read, and Execute access to CD/DVD drive, but Allow Read. .OUTPUTS None .NOTES Minimum OS Architecture Supported: Windows 7, Windows Server 2012 Local Group Policy updates like this requires the computer to rebooted. Release Notes: Renamed script and added Script Variable support 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). .COMPONENT DataIOSecurity #> [CmdletBinding()] param ( # Supported devices Floppy, DVD, Tape, WPD, USB [String[]] $Device, [switch] $DenyRead = [System.Convert]::ToBoolean($env:DenyRead), [switch] $DenyWrite = [System.Convert]::ToBoolean($env:DenyWrite), [switch] $DenyExecute = [System.Convert]::ToBoolean($env:DenyExecute), [switch] $AllowRead = [System.Convert]::ToBoolean($env:AllowRead), [switch] $AllowWrite = [System.Convert]::ToBoolean($env:AllowWrite), [switch] $AllowExecute = [System.Convert]::ToBoolean($env:AllowExecute), [switch] $ForceReboot = [System.Convert]::ToBoolean($env:ForceReboot) ) begin { function Test-StringEmpty { param([string]$Text) # Returns true if string is empty, null, or whitespace process { [string]::IsNullOrEmpty($Text) -or [string]::IsNullOrWhiteSpace($Text) } } function Test-IsElevated { $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() $p = New-Object System.Security.Principal.WindowsPrincipal($id) $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) } $RegSettings = @( [PSCustomObject]@{ Name = "Floppy" BasePath = "HKLM:\Software\Policies\Microsoft\Windows\RemovableStorageDevices\{53f56311-b6bf-11d0-94f2-00a0c91efb8b}" DenyExecute = "Deny_Execute" DenyWrite = "Deny_Write" DenyRead = "Deny_Read" }, [PSCustomObject]@{ Name = "DVD" BasePath = "HKLM:\Software\Policies\Microsoft\Windows\RemovableStorageDevices\{53f56308-b6bf-11d0-94f2-00a0c91efb8b}" DenyExecute = "Deny_Execute" DenyWrite = "Deny_Write" DenyRead = "Deny_Read" }, [PSCustomObject]@{ Name = "Tape" BasePath = "HKLM:\Software\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630b-b6bf-11d0-94f2-00a0c91efb8b}" DenyExecute = "Deny_Execute" DenyWrite = "Deny_Write" DenyRead = "Deny_Read" }, [PSCustomObject]@{ Name = "WPD" BasePath = "HKLM:\Software\Policies\Microsoft\Windows\RemovableStorageDevices\{6AC27878-A6FA-4155-BA85-F98F491D4F33}" DenyWrite = "Deny_Write" DenyRead = "Deny_Read" }, [PSCustomObject]@{ Name = "WPD" BasePath = "HKLM:\Software\Policies\Microsoft\Windows\RemovableStorageDevices\{F33FDC04-D1AC-4E8E-9A30-19BBD4B108AE}" DenyWrite = "Deny_Write" DenyRead = "Deny_Read" }, [PSCustomObject]@{ Name = "USB" BasePath = "HKLM:\Software\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}" DenyExecute = "Deny_Execute" DenyWrite = "Deny_Write" DenyRead = "Deny_Read" } ) $Device = if ($(Test-StringEmpty -Text $env:Device)) { $Device }else { $env:Device } if ($(Test-StringEmpty -Text $Device)) { Write-Error "Device is required." exit 1 } if ((-not $DenyRead -and -not $DenyWrite -and -not $DenyExecute) -and (-not $AllowRead -and -not $AllowWrite -and -not $AllowExecute)) { Write-Error "At least one Deny or Allow is required." exit 1 } } process { if (-not (Test-IsElevated)) { Write-Error -Message "Access Denied. Please run with Administrator privileges." exit 1 } # Split any string that has a comma and validate types of devices $Device = $Device | ForEach-Object { $_ -split ',' | ForEach-Object { "$_".Trim() } } | Where-Object { $_ -in "Floppy", "DVD", "Tape", "WPD", "USB" } try { $Device | ForEach-Object { $CurDevice = $_ # Loop through each item in $RegSettings and work on the current device($Device) $RegSettings | Where-Object { $_.Name -in $CurDevice } | ForEach-Object { $CurRegSetting = $_ $Path = $CurRegSetting.BasePath # Build Deny list $Deny = [System.Collections.ArrayList]::new() # Older PowerShell compatible Lists if ($DenyRead) { $Deny.Add("Read") | Out-Null } if ($DenyWrite) { $Deny.Add("Write") | Out-Null } if ($DenyExecute) { $Deny.Add("Execute") | Out-Null } # Build Allow list $Allow = [System.Collections.ArrayList]::new() # Older PowerShell compatible Lists if ($AllowRead) { $Allow.Add("Read") | Out-Null } if ($AllowWrite) { $Allow.Add("Write") | Out-Null } if ($AllowExecute) { $Allow.Add("Execute") | Out-Null } # Loop though each $Deny item passed $Deny | ForEach-Object { $CurDeny = $_ # Only act on what we have, like WPD where we only have Deny_Write and Deny_Read # $CurRegSetting."Deny$CurDeny" is a method of access a property if ($CurRegSetting."Deny$CurDeny") { $CurDenyType = $CurRegSetting."Deny$CurDeny" # Check if we need to create the path if (-not (Test-Path -Path $Path -ErrorAction SilentlyContinue)) { New-Item -Path ($Path | Split-Path -Parent) -Name ($Path | Split-Path -Leaf) -Force -Confirm:$false | Out-Null Write-Host "Creating path: $($Path)" } # Check if the property already exists and update it or create the property if ((Get-ItemProperty -Path $Path -Name $CurDenyType -ErrorAction SilentlyContinue)."$CurDenyType") { Set-ItemProperty -Path $Path -Name $CurDenyType -Value 1 -Force -Confirm:$false | Out-Null Write-Host "Setting $($Path)/$CurDenyType to 1" } else { New-ItemProperty -Path $Path -Name $CurDenyType -Value 1 -PropertyType "DWORD" -Force -Confirm:$false | Out-Null Write-Host "Creating and Setting $($Path)/$CurDenyType to 1" } Write-Host "Deny $CurDeny for $CurDevice set to $((Get-ItemProperty -Path $Path -Name $CurDenyType -ErrorAction SilentlyContinue)."$CurDenyType")" } else { # Skipping this as we don't have Deny_Execute for WPD Write-Host "Skipping $($CurRegSetting."Deny$CurDeny")" } } # Loop though each $Allow item passed $Allow | ForEach-Object { $CurAllow = $_ # Only act on what we have, like WPD where we only have Deny_Write and Deny_Read # $CurRegSetting."Deny$CurAllow" is a method to access a property if ($CurRegSetting."Deny$CurAllow") { $CurAllowType = $CurRegSetting."Deny$CurAllow" # Check if the property already exists and update it or create the property if ((Get-ItemProperty -Path $Path -Name $CurAllowType -ErrorAction SilentlyContinue)."$CurAllowType") { Set-ItemProperty -Path $Path -Name $CurAllowType -Value 0 -Force -Confirm:$false | Out-Null Write-Host "Setting $($Path)/$CurAllowType to 0" } Write-Host "Allow access for $CurDevice" } else { # Skipping this as we don't have Deny_Execute for WPD Write-Host "Skipping $($CurRegSetting."Deny$CurAllow")" } } } } Write-Host "Running: gpupdate.exe /force" gpupdate.exe /force Write-Host "Completed Running: gpupdate.exe /force" Write-Host "Computer will need to be rebooted for changes to take effect." if ($ForceReboot) { shutdown.exe -r -t 60 } else { Write-Host "Computer will need to be rebooted to see changes." } exit 0 } catch { Write-Error $_ exit 1 } } end { }
Greifen Sie auf über 300 Skripte im NinjaOne Dojo zu.
Detaillierte Aufschlüsselung
Das Skript arbeitet in mehreren unterschiedlichen Phasen:
- Definition der Parameter: Sie beginnt mit der Definition von Parametern für verschiedene Gerätetypen und Aktionen, wie etwa das Verweigern oder Zulassen vom Lesen, Schreiben, Ausführen.
- Kontrollen vor der Ausführung: Es enthält Funktionen zur Prüfung auf leere Zeichenfolgen und zur Überprüfung, ob das Skript mit Administratorrechten ausgeführt wird.
- Anpassungen der Registrierungseinstellungen: Die Kernfunktionalität besteht darin, die Registrierungseinstellungen für jeden Gerätetyp zu ändern. Diese Einstellungen bestimmen die Berechtigungen für jede Aktion (Lesen, Schreiben, Ausführen).
- Ausführungslogik: Das Skript erstellt oder ändert Registrierungsschlüssel und -werte auf der Grundlage der Eingabeparameter. Sie kann Berechtigungen festlegen, um Aktionen auf den angegebenen Geräten entweder zu verweigern oder zu erlauben.
- Letzte Schritte: Das Skript schließt mit der Aktualisierung der Gruppenrichtlinien mit gpupdate.exe und optional mit einem Neustart des Systems ab, damit die Änderungen wirksam werden.
Mögliche Anwendungsfälle
Denken Sie an ein Finanzunternehmen, das sich an strenge Datensicherheitsvorschriften halten muss. Ein IT-Administrator kann mit diesem Skript den Schreibzugriff auf USB-Laufwerke an allen Workstations deaktivieren und so verhindern, dass sensible Daten auf externe Geräte kopiert werden.
Vergleiche
Herkömmliche Methoden zur Konfiguration von Geräteberechtigungen können in manuellen Registrierungsänderungen oder Gruppenrichtlinienkonfigurationen bestehen. Dieses Skript automatisiert diese Prozesse, verringert die Fehlerquote und spart Zeit.
FAQs
- Ist das Skript mit allen Windows-Versionen kompatibel?
- Es unterstützt Windows 7 und höher, einschließlich der Server-Editionen.
- Kann es den Zugriff auf Netzwerklaufwerke kontrollieren?
- Nein, es ist speziell für Wechseldatenträger gedacht.
- Erfordert das Skript Administratorrechte?
- Ja, es muss mit Administratorrechten ausgeführt werden.
Folgen
Dieses Skript ist zwar ein leistungsfähiges Tool zur Verbesserung der Datensicherheit, birgt aber auch das Risiko, den Zugriff zu stark einzuschränken, was legitime Arbeitsabläufe behindern könnte. Es ist wichtig, die Sicherheitsanforderungen mit den betrieblichen Anforderungen in Einklang zu bringen.
Empfehlungen
- Testen Sie das Skript in einer Staging-Umgebung, bevor Sie es in großem Umfang einsetzen.
- Dokumentieren Sie alle mit dem Skript vorgenommenen Änderungen für künftige Referenzen.
- Überprüfen und aktualisieren Sie die Zugangsrichtlinien regelmäßig, um sie an die sich verändernden Sicherheitsanforderungen anzupassen.
Abschließende Überlegungen
In der heutigen dynamischen IT-Welt können Tools wie NinjaOne Skripte wie dieses ergänzen, indem es eine integrierte Plattform für die Verwaltung von IT-Betrieb, einschließlich Sicherheitskonfigurationen, angeboten wird. Die Fähigkeit von NinjaOne, Verwaltungsaufgaben zu zentralisieren, stellt sicher, dass Sicherheitsrichtlinien in der gesamten IT-Infrastruktur konsistent angewendet werden, was die allgemeine Sicherheit und betriebliche Effizienz erhöht.