Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Last pieces of the puzzle converting diskpart script to PowerShell storage cmdlets

$
0
0

The Basic Windows Deployment Step-by-Step Guide provides a script for recommended UEFI/GPT drive partitions as follows:

rem These commands are used with DiskPart to
rem erase the drive and create five partitions
rem for a UEFI/GPT-based computer.
rem Adjust the partition sizes to fill the drive as necessary.
select disk 0
clean
convert gpt
rem === 1. Windows RE tools partition ===========
create partition primary size=300
format quick fs=ntfs label="Windows RE tools"
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
assign letter="T"
rem === 2. System partition =====================
create partition efi size=100
format quick fs=fat32 label="System"
assign letter="S"
rem === 3. Microsoft Reserved (MSR) partition ===
create partition msr size=128
rem === 4. Windows partition ====================
rem ==    a. Create Windows partition ===========
create partition primary
rem ==    b. Create space for recovery image ==== 
shrink minimum=15000
rem ==    c. Prepare the Windows partition ======
format quick fs=ntfs label="Windows"
assign letter="W"
rem === 5. Recovery image partition =============
create partition primary
format quick fs=ntfs label="Recovery image"
gpt attributes=0x8000000000000001
assign letter="R"

I would like to convert this to an equivalent sequence of PowerShell storage cmdlets, and have developed the following:

Clear-Disk 0 -RemoveData -RemoveOEM
Initialize-Disk 0 –PartitionStyle GPT
$windowsPartitionSize = ( Get-Disk 0 ).Size - 300MB - 100MB - 128MB - 15000MB
New-Partition 0 -GptType 'de94bba4-06d1-4d40-a16a-bfd50179d6ac' -Size 300MB -DriveLetter T | Format-Volume -FileSystem NTFS -NewFileSystemLabel WindowsRE
New-Partition 0 -GptType 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' -Size 100MB -DriveLetter S | Format-Volume -FileSystem FAT32 -NewFileSystemLabel System
New-Partition 0 -GptType 'e3c9e316-0b5c-4db8-817d-f92df00215ae' -Size 128MB
New-Partition 0 -GptType 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' -Size $windowsPartitionSize -DriveLetter W | Format-Volume -FileSystem NTFS -NewFileSystemLabel Windows
New-Partition 0 -GptType 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' -UseMaximumSize -DriveLetter R | Format-Volume -FileSystem NTFS -NewFileSystemLabel Recovery
# gpt attributes=0x8000000000000001

My question is how to express the diskpart command "gpt attributes=0x8000000000000001" using PowerShell. The Storage cmdlets are described here, but I can't find anything relating to the latter.

In a similar vein, there is a second diskpart script with Recommended BIOS/MBR Disk Partitions. In that script there is a diskpart command "attributes volume set nodefaultdriveletter". Again it isn't clear how to express this in PowerShell. Set-Partition has a -NoDefaultDriveLetter parameter, but this is said to apply only to GPT parttions.

Any advice would be appreciated. Thanks. Jeff.



Jeffry A. Spain Network Administrator Cincinnati Country Day School


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>