Created
August 25, 2018 20:14
-
-
Save newyear2006/c994271380c9cbc98456f12e27ada6de to your computer and use it in GitHub Desktop.
Konvertiert Linux-SCSI Devicenamen wie /dev/sda nach Windows PhysicalDrive0 Namen und zurück
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Konvertiert Linux-SCSI Devicenamen nach Windows PhysicalDrive Namen und zurück | |
Function Convert-LinuxDeviceAndWinPhysicalDrive { | |
Param( | |
[string]$deviceOrDisk | |
) | |
If ($deviceOrDisk.ToLower().IndexOf("physicaldisk") -eq 0) { | |
$number = [int]$deviceOrDisk.Substring(12) | |
If ($number -gt 25) { | |
Write-Error ">25 unsupported!" | |
throw | |
} | |
"/dev/sd$([char]([int][char]'a' + ($number)))" | |
} else { | |
If ($deviceOrDisk.IndexOf("/dev/") -eq 0) { | |
# /dev/ ist optional! | |
$deviceOrDisk=$deviceOrDisk.Substring(5) | |
} | |
If ($deviceOrDisk.IndexOf("sd") -ne 0) { | |
Write-Error "nur [/dev/]sd[a-z] wird unterstützt!" | |
throw | |
} | |
$number = $deviceOrDisk.Substring(2) | |
If ($number.Length -gt 1) { | |
Write-Error "$deviceOrDisk unsupported!" | |
throw | |
} | |
"PhysicalDisk$([int][char]$number-[int][char]'a')" | |
} | |
} | |
#funktionierende Beispiele zum Testen: | |
$device = "/dev/sda" | |
Convert-LinuxDeviceAndWinPhysicalDrive $device | |
Convert-LinuxDeviceAndWinPhysicalDrive (Convert-LinuxDeviceAndWinPhysicalDrive $device) | |
$device = "sda" | |
Convert-LinuxDeviceAndWinPhysicalDrive $device | |
Convert-LinuxDeviceAndWinPhysicalDrive (Convert-LinuxDeviceAndWinPhysicalDrive $device) | |
$device = "PhysicalDisk0" | |
Convert-LinuxDeviceAndWinPhysicalDrive $device | |
Convert-LinuxDeviceAndWinPhysicalDrive (Convert-LinuxDeviceAndWinPhysicalDrive $device) | |
# nicht funktionierende Beispiele wo Fehler erzeugen: | |
$device = "PhysicalDisk26" | |
Convert-LinuxDeviceAndWinPhysicalDrive $device | |
Convert-LinuxDeviceAndWinPhysicalDrive (Convert-LinuxDeviceAndWinPhysicalDrive $device) | |
$device = "sdaa" | |
Convert-LinuxDeviceAndWinPhysicalDrive $device | |
Convert-LinuxDeviceAndWinPhysicalDrive (Convert-LinuxDeviceAndWinPhysicalDrive $device) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment