Customised diskpart - search and partition SSD

Page 1 of 2 12 LastLast

  1. Posts : 6
    Windows 10 Enterprise
       #1

    Customised diskpart - search and partition SSD


    Hello everyone,

    I am doing new images for our company, and using WinPe to automate things.

    Usually and most of the PC that we deploy have only one disk, and than the default microsoft script does good job for me:

    Code:
    rem == CreatePartitions-UEFI.txt ==
    rem == These commands are used with DiskPart to
    rem    create four partitions
    rem    for a UEFI/GPT-based PC.
    rem    Adjust the partition sizes to fill the drive
    rem    as necessary. ==
    select disk 0
    clean
    convert gpt
    rem == 1. System partition =========================
    create partition efi size=100
    rem    ** NOTE: For Advanced Format 4Kn drives,
    rem               change this value to size = 260 ** 
    format quick fs=fat32 label="System"
    assign letter="S"
    rem == 2. Microsoft Reserved (MSR) partition =======
    create partition msr size=16
    rem == 3. Windows partition ========================
    rem ==    a. Create the Windows partition ==========
    create partition primary 
    rem ==    b. Create space for the recovery tools ===
    rem       ** Update this size to match the size of
    rem          the recovery tools (winre.wim)
    rem          plus some free space.
    shrink minimum=500
    rem ==    c. Prepare the Windows partition ========= 
    format quick fs=ntfs label="Windows"
    assign letter="W"
    rem === 4. Recovery partition ======================
    create partition primary
    format quick fs=ntfs label="Recovery"
    assign letter="R"
    set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
    gpt attributes=0x8000000000000001
    list volume
    exit
    But the issue is when PC has one HDD and one SSD, and than usually SSD is disk1 not disk0. So I was wondering if anyone can help me to modify this script to automatically search for SSD and to partition SSD instead of HDD.

    Thanks in advance

    Windwos Pro 2004
      My Computer


  2. Posts : 7,607
    Windows 10 Home 20H2
       #2

    Will the script be run on Windows PE or installed Windows 10?
    PowerShell can search for an SSD, but I wonder whether your Windows PE has PowerShell.
    My Windows PE has no PowerShell.

    PowerShell Get-PhysicalDisk ^| Select MediaType, DeviceID, FriendlyName

    The above command can find SSDs and HDDs.
    I have used it in the following script:

    Batch files for use in BSOD debugging
      My Computer


  3. Posts : 6
    Windows 10 Enterprise
    Thread Starter
       #3

    Hi,

    I would lite to use it in WinPe environment, during deployment. I edited my WinPe in order for it to have powershell, but unsure how to wrap this all in one batch, or powershell script...

    EDIT:

    So it seems that this PS script is able to determine SSD that is larger than 100GB

    Code:
     $MainDisk = 0
     ForEach ($disk in (Get-PhysicalDisk | Select-Object DeviceID, MediaType, Size)){
         If ($disk.MediaType -eq 'SSD' -and $disk.Size -gt 100GB){
             $MainDisk = $disk.DeviceID
             break
         }
     }
    All I need now is to connect the two scripts to work together...
    Last edited by ssivic; 25 Sep 2020 at 07:32. Reason: new things found
      My Computer


  4. Posts : 2,799
    Linux Mint 20.1 Win10Prox64
       #4

    You can try: wmic diskdrive get index,caption | find "SSD" | sort
    Customised diskpart - search and partition SSD-image.png
    So if you have 1 HD and 1 SSD then the output will give you one single line
    where you can identify the disk #.
      My Computer


  5. Posts : 7,607
    Windows 10 Home 20H2
       #5

    Are you sure that the captions of all SSDs must include the term "SSD"?
      My Computer


  6. Posts : 7,607
    Windows 10 Home 20H2
       #6

    ssivic said:
    All I need now is to connect the two scripts to work together...

    The two scripts in the following ZIP file will work together.

    Testing.zip


    Download it and extract the files. The INP file has the following line:

    select disk X

    Run the CMD file and see whether the above X has been replaced with the disk number of your SSD.

    If it works, the INP and CMD files can then be combined into a single file.
    Customised diskpart - search and partition SSD Attached Files
      My Computer


  7. Posts : 6
    Windows 10 Enterprise
    Thread Starter
       #7

    Thank you, will check it out as soon as I get back in office and let you know. in the meantime I was trying to do something like this, but not if it will work. A all in one PS script to select SSD that is over 100GB and than partition it...

    $MainDisk = 0
    ForEach ($disk in (Get-PhysicalDisk | Select-Object DeviceID, MediaType, Size)){
    If ($disk.MediaType -eq 'SSD' -and $disk.Size -gt 100GB){
    $MainDisk = $disk.DeviceID
    $prepdisk=@(
    'select vol $MainDisk',
    'clean'
    'convert gpt'
    'create partition efi size=100'
    'format quick fs=fat32 label="System"'
    'assign letter="S"'
    'create partition msr size=16'
    'create partition primary'
    'shrink minimum=500'
    'format quick fs=ntfs label="Windows"'
    'assign letter="W"'
    'create partition primary'
    'format quick fs=ntfs label="Recovery"'
    'assign letter="R"'
    'set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"'
    'gpt attributes=0x8000000000000001'
    'list volume'
    )
    $prepdisk | diskpart
    break
    }
    }
      My Computer


  8. Posts : 7,607
    Windows 10 Home 20H2
       #8

    ssivic said:
    A all in one PS script to select SSD that is over 100GB and than partition it...
    The following CMD script will select an SSD but will not check the disk capacity.
    Code:
    For /f "Skip=3 usebackq tokens=1,2" %%A in ( ^
    `"PowerShell Get-PhysicalDisk ^| Select MediaType, DeviceID"`) Do (
    If %%A==SSD Call:Job %%B)
    Exit
    :Job
    (
    Echo select disk %1
    Echo clean
    Echo convert gpt
    Echo create partition efi size=100
    Echo format quick fs=fat32 label="System"
    Echo assign letter="S"
    Echo create partition msr size=16
    Echo create partition primary
    Echo shrink minimum=500
    Echo format quick fs=ntfs label="Windows"
    Echo assign letter="W"
    Echo create partition primary
    Echo format quick fs=ntfs label="Recovery"
    Echo assign letter="R"
    Echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
    Echo gpt attributes=0x8000000000000001
    Echo list volume
    Echo exit
    )|DisKPart
      My Computer


  9. Posts : 2,799
    Linux Mint 20.1 Win10Prox64
       #9

    Matthew Wai said:
    Are you sure that the captions of all SSDs must include the term "SSD"?
    True. Not all SSD's contain the string "SSD", my OCZ is SSD. Use this instead:
    wmic /NameSpace:\\root\Microsoft\Windows\Storage Path MSFT_PhysicalDisk Where "MediaType='4' And SpindleSpeed='0'" Get DeviceID,Model

    Customised diskpart - search and partition SSD-image.png
      My Computer


  10. Posts : 7,607
    Windows 10 Home 20H2
       #10

    It is not difficult to find an SSD but difficult to compare the capacity because CMD does not support such a large number as 107400000000 (= 100 GB).
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:43.
Find Us




Windows 10 Forums