none
Automatisierte Installation von Windows 2012 R2 mit Powershell RRS feed

  • Frage

  • Hallo,

    ich versuche mithilfe von Powershell 4.0 eine Windows Server 2012 R2 Installation zu automatisieren. Bis zu der Stelle, an der ich mein RAID konfigurieren möchte, funktioniert alles wunderbar.

    Eigentlich ist mein Skript so aufgebaut, dass es zuerst herausfindet welches das System Volume und welches das Windows Volume ist. Danach initialisiert und konvertiert es alle notwendigen Festplatten um das RAID zu bauen.

    Allerdings spiegeltWindows nun nicht zuerst das System Volume, sondern das Windows Volume, wodurch für das System Volume kein Platz mehr am Anfang der Festplatte zur Verfügung steht.

    Führe ich mein Skript manuell aus (mit einem Doppelklick auf die .ps1 Datei) läuft alles wunderbar durch.

           Write-Host "Starting now with creating RAID1"
            New-Item C:\Windows\install_diskpart.log -Type File
        
            "-- Starting now with creating RAID1" >> C:\windows\install.log
    
            $volumes = "list volume" | diskpart | ? { $_ -match "^ [^-]" -AND $_ -notmatch "###" -AND $_ -notmatch "-" }
            $volumes >> C:\Windows\install_diskpart.log
    
            foreach ($row in $volumes) {
                if ($row -like "*Windows*"){
                    $winvol = $row -split "\s+" | where {$_ -match "^[0-9]{1}$"}
                    "-- $winvol is reserved for windows" >> C:\windows\install.log
                }
                if ($row -like "*System*"){
                    $sysvol = $row -split "\s+" | where {$_ -match "^[0-9]{1}$"}
                    "-- $sysvol is reserved for system" >> C:\windows\install.log 
                }
            }
    
            Write-Host "SystemVolume: $sysvol | WindowsVolume: $winvol"
            
            ## Diskpart vorbereiten
            $sysdis = (echo "sel vol $sysvol" "detail vol" | diskpart | where {$_ -match "^\*" -and $_ -match ".[a-z]{4,}.\s+[0-9]{1}"}) -split "\s+" | where {$_ -match "[0-9]{1}"} # getting disk id, disk size and free diskspace
            $raiddisk = echo "lis dis" | diskpart | where { $_ -match "^ [^-]" -AND $_ -notmatch "###" -AND $_ -notmatch "-" -and $_ -match $sysdis[1] } # find the second disk with the exact size of the sysdisk for creating the raid
    
            foreach ($pdisk in $raiddisk){
                $pdisk = $pdisk -split "\s+" | where {$_ -match "^[0-9]{1}$"}
                if ($pdisk[0] -ne $sysdis[0]){
                    $mirrordisk = $pdisk[0]
                    $systemdisk = $sysdis[0]
                    $command = echo "sel dis $pdisk" "clean" "convert dynamic" | diskpart # cleaning the other raid disk not the system disk
                    $command >> C:\Windows\install_diskpart.log
                    sleep 2
                    $command = echo "sel dis $systemdisk" "convert dynamic" | diskpart # convert systemdisk to dynamic disk
                    $command >> C:\Windows\install_diskpart.log
                    sleep 2
                    $command = echo "sel dis $systemdisk" "convert dynamic" | diskpart # convert systemdisk to dynamic disk
                    $command >> C:\Windows\install_diskpart.log
                    sleep 2
                    $command = echo "rescan" | diskpart # rescanning to have the actual disk config for sure
                    $command >> C:\Windows\install_diskpart.log
                    sleep 2
                    $command = echo "sel dis $systemdisk"  "sel vol $sysvol" "add disk=$mirrordisk"  | diskpart # adding the raid partition for sysvol dynamically
                    $command >> C:\Windows\install_diskpart.log
                    sleep 2
                    $command = echo "sel dis $systemdisk" "sel vol $winvol" "add disk=$mirrordisk" | diskpart # adding the raid partition for winvol dynamically
                    $command >> C:\Windows\install_diskpart.log
                    sleep 2
                }
    
            }
    
            $dp = echo "lis vol" | diskpart | where { $_ -match "^ [^-]" -AND $_ -notmatch "###" -AND $_ -notmatch "-" }
            foreach ($row in $dp) {
                if ($row -notmatch "Mirror|RAID-5|Stripe|Spiegel|Spiegelung|Übergreifend|Spanned") {
                    $failed = $true
                }
            }
    
            $disk = echo "lis dis" | diskpart | where { $_ -match "^ [^-]" -AND $_ -notmatch "###" -AND $_ -notmatch "-" } # find all disks
    
            foreach ($row in $disk){
                $row = $row -split "\s+" | where {$_ -match "^[0-9]{1}$"}
                if ($row[0] -ne $sysdis[0] -and $row[0] -ne $mirrordisk){
                    $dis = $row[0]
                    $i = 0
                    $letter = @("e","f","g","h")
                    $command = echo "sel dis $dis" "clean" "create partition primary" "format fs=ntfs quick" "letter $letter" | diskpart #format all other disks and assign drive letter
                    $i++
                }
            }

    Vielleicht weiß ja jemand Rat. :)

    Vielen Dank schonmal

    • Verschoben Alex Pitulice Dienstag, 3. Dezember 2013 10:24 Verschoben
    Montag, 2. Dezember 2013 14:55

Antworten

  • Hallo,

    ich muss den Thread mal aus der Versenkung heben.

    Die Lösung war eigentlich ziemlich einfach. Während des Setup Prozesses scheint Powershell anders zu arbeiten, als während der eigentlichen Client-Session. Wenn man nun also die Reihenfolge in der das RAID erzeugt wird vertauscht, so legt Powershell zuerst die eigentliche Windows-Partition und dann erst die System-Partition an und erzeugt daraus dann in der richtigen Reihenfolge das Software-RAID.

    Freitag, 17. Oktober 2014 10:43

Alle Antworten