Install OS and format other hard disk if user prompt is yes


  1. Posts : 32
    windows 10
       #1

    Install OS and format other hard disk if user prompt is yes


    Hi Experts,

    I am Bala, working on Windows 10 20H2 image creation and deployment, where i will be creating the wim file & using the wim file we will apply the image to pc. we are not using SCCM or MDT deployment since the PC will be deployed in a stand alone environments mostly. User of the PC will have the USB for OS installation.

    I was using the bat file to complete the OS installation and making partitions. Now i have got an issue where i have more than 2 HDD(non RIAD) present in the pc, where operating system should be installed in disk 0 and if user gives input as Yes the Disk 1 and disk 2 should be formatted. where the number of disk might increase or decrease so i am looking to find is there a way where we can dynamically perform this operation.

    Kindly suggest your inputs please.

    Thanks
    Balaji

    - - - Updated - - -

    Hi Experts,

    I am using the below given for command for formatting the OS installation disk. using diskpart formatting the disk and os will be installed in disk 0.

    "rem == CreatePartitions-UEFI.txt ==

    select disk 0
    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
    format quick fs=ntfs label="Windows"
    assign letter="W"
    list volume

    exit "

    for formatting additional disk i am using the below bat file
    (
    Echo select disk %1
    Echo clean
    Echo convert gpt
    Echo create partition primary
    Echo format quick fs=NTFS
    Echo assign
    Echo exit
    )|Diskpart

    exit /b

    this formats the OS installed disk as well. so we need to find an option to that this skips the the OS installed disk.

    Thanks
    Balaji S
      My Computer


  2. Posts : 494
    Win 10 Pro x64 versions
       #2

    Why are you including the % in front of the 1 in select disk? % is not valid in diskpart
      My Computer


  3. Posts : 32
    windows 10
    Thread Starter
       #3

    Hi Railtech,

    In winpe we have included the powershell so the below script is working fine. actually while updating the batch file i missed the initial part. since the HDD present in the pc is more than one so only i am using this option.

    For /f "Skip=3 usebackq tokens=1,2" %%A in ( ^
    `"PowerShell Get-PhysicalDisk ^| Select MediaType, DeviceID"`) Do (
    if %%A==HDD Call:HDD %%B)

    Exit

    :HDD
    (
    Echo select disk %1
    Echo clean
    Echo convert gpt
    Echo create partition primary
    Echo format quick fs=NTFS
    Echo assign
    Echo exit
    )|DisKPart
    EXIT /B

    now in this i need to exclude disk 0. since OS is installed in the Disk 0.

    Thanks
    Balaji S
      My Computer


  4. Posts : 7,484
    Windows 10 Home 20H2
       #4

    ijalabs said:
    i need to exclude disk 0.
    Code:
    For /f "Skip=3 tokens=1,2" %%A in (
    '"PowerShell Get-PhysicalDisk^|Select MediaType, DeviceID"') Do (
    if %%A==HDD If not %%B==0 Call:HDD %%B)
    Exit
    
    :HDD
    REM <Write the DiskPart commands below.>

    Railtech said:
    Why are you including the % in front of the 1 in select disk? % is not valid in diskpart
    %1 will be equal to %%B, a variable standing for the disk number retrieved by PowerShell Get-PhysicalDisk
      My Computer


  5. Posts : 494
    Win 10 Pro x64 versions
       #5

    Code:
    For /f "Skip=3 tokens=1,2" %%A in (
    '"PowerShell Get-PhysicalDisk^|Select MediaType, DeviceID"') Do (
    if %%A==HDD If not %%B==0 Call:HDD %%B)
    Exit

    :HDD
    REM <Write the DiskPart commands below.>

    MediaType may not work as disk drive may not be HDD. Could be SSD or other. Probably best to use just the DeviceID.
      My Computer


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

    The OP wrote "HDD" rather than "SSD". If the OP uses both HDDs and SSDs or others, the code can be modified accordingly.
      My Computer


  7. Posts : 494
    Win 10 Pro x64 versions
       #7

    The OP wrote "HDD" rather than "SSD". If the OP uses both HDDs and SSDs or others, the code can be modified accordingly.
    Sure can. Trouble I see is that the OP implies that this is intended to be a mass production process. Given that then neither deviceid nor mediatype are appropriate. I would say the OP needs an application that can facilitate deployment of this nature. I doubt it can be done using the free tools available such as diskpart and PS on a large scale.
      My Computer


  8. Posts : 32
    windows 10
    Thread Starter
       #8

    Matthew Wai said:
    Code:
    For /f "Skip=3 tokens=1,2" %%A in (
    '"PowerShell Get-PhysicalDisk^|Select MediaType, DeviceID"') Do (
    if %%A==HDD If not %%B==0 Call:HDD %%B)
    Exit
    
    :HDD
    REM <Write the DiskPart commands below.>

    %1 will be equal to %%B, a variable standing for the disk number retrieved by PowerShell Get-PhysicalDisk
    This solution has solved the issues that i had. really thanks for the fix.
      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 22:58.
Find Us




Windows 10 Forums