Automating installation rename optical and SSD/HDD during post install

Page 2 of 3 FirstFirst 123 LastLast
  1. Ztruker's Avatar
    Posts : 8,817
    Windows 10 Pro X64 1903 18362.295
       #11

    If you can determine via your script what the disk and partition numbers are you could use diskpart by stacking the responses then calling diskpart, something like this: (swiped from a bat file from @hsehestedt):

    (echo select disk %DiskID%
    echo select partition 1
    echo assign letter=Q
    echo select partition 2
    echo assign letter=R
    echo exit
    ) | diskpart > nul
      My ComputersSystem Spec

  2. Compumind's Avatar
    Posts : 1,308
    Windows 10 Pro x64, Various Linux Builds, Internet Security Specialty.
       #12

    Wobitancrawfodi said: View Post
    I'm getting dizzy.

    I didn't ask the question here without having gone looking for the answer myself. I've spent a lot of time developing my script. That would have been near impossible without the Microsoft docs, and help from users at MDL, Bleeping Computer and so on. But the one question I can't find an answer to is "How to change/reassign a drive letter from the command line".

    I started the script when 1703 came out. The link that you provided is a place I spent a lot of time, as well as privacy and security settings sites (including Microsoft's), group policy settings and a number of websites dealing with security, hardening Windows and powershell, DISM and WMIC references.

    Though all of those travels I cannot find the answer to that one question.

    Does that make things crystal clear now?
    Extremely crystal.

    I wouldn't mind helping you with this but your candor is way disappointing to me.
    Perhaps someone else would like to jump in.

    Cheers.

      My ComputerSystem Spec


  3. Posts : 48
    Windows 10 x64 1809
    Thread Starter
       #13

    Ztruker said: View Post
    If you can determine via your script what the disk and partition numbers are you could use diskpart by stacking the responses then calling diskpart, something like this: (swiped from a bat file from @hsehestedt):

    (echo select disk %DiskID%
    echo select partition 1
    echo assign letter=Q
    echo select partition 2
    echo assign letter=R
    echo exit
    ) | diskpart > nul
    Yes, I was thinking along the same lines. Near as I can tell Windows is inconsistent with how it allocates disk numbers when there are M.2 SSDs in the system. I was looking at trying to use WMIC to get the diskdrive details and store them in variables then based on whose computer the script is running on select the correct diskpart script. I'd need a script for each PC and each drive in each PC.

    That unravels when a PC has multiple M.2 drives of the same model. If they are different sizes I'd need to grab the size as well. Or maybe I can grab the serial via wmic or some other unique detail that identifies each drive.

    Some motherboards disable SATA Ports when certain M.2 slots are used. Since not all motherboards here are the same I get different results for each PC. As if that wasn't enough, the USB stick that I'm installing from also has two drive letters allocated. One for the UEFI partition which doesn't need a drive letter. So on a system with 2 Opticals I lose drives D: through G: immediately after a clean install. So I have to rename them first, remove the drive letter from the USB UEFI, then reassign the real drives I want.

    One of the reasons I was hoping there would be a simple solution that I'd missed.

    "wmic diskdrive" gives me the drives details. Index (Drive #), serial number and the number of partitions on the drive. There is a mismatch between diskpart and wmic. For boot drives diskpart lists 3 system partitions, whereas wmic reports the same as what you see in disk management - only 2 such partitions (wmic does not see the 16mb reserved partition).

    Diskpart supports the /s switch which allows you to load the commands from a text file.
    Only the SSD with C: drive has two user partitions (or 5 if you count the recovery, system and reserved partitions that don't use drive letters). All others have one. One small mercy I suppose :)
      My ComputerSystem Spec

  4. Ztruker's Avatar
    Posts : 8,817
    Windows 10 Pro X64 1903 18362.295
       #14

    There has to be a better way, but it will still depend on your ability to suss out the drives/drive types and partitions dynamically, unless you can create a file for each system and feed it to diskpart using /s as you mentioned. Should be possible if there are only 10 machines and you are not changing hardware in the machines except due to failure.
      My ComputersSystem Spec


  5. Posts : 48
    Windows 10 x64 1809
    Thread Starter
       #15

    Ztruker said: View Post
    There has to be a better way,
    Sir, you have hit the proverbial nail on the head. Exactly why I asked here.

    A simple solution seems extremely elusive. I suppose I better start coding.. This is going to take quite a while As you said, I'm going to have to visit each PC and get the serial number of every drive and Build a table of all drives/partitions and letters and code around that.

    I will of course need to "failure proof" the code. If PC #1 should have drive with serial 12345 and that serial cannot be found, catastrophic abort
      My ComputerSystem Spec

  6. Ztruker's Avatar
    Posts : 8,817
    Windows 10 Pro X64 1903 18362.295
       #16

    Powershell get-wmiobject could be a starting point:

    Code:
    > get-wmiobject -class win32_logicaldisk
    
    DeviceID     : C:
    DriveType    : 3
    ProviderName :
    FreeSpace    : 186920497152
    Size         : 448944750592
    VolumeName   : Lenovo_C
    
    DeviceID     : D:
    DriveType    : 3
    ProviderName :
    FreeSpace    : 690810855424
    Size         : 786567241728
    VolumeName   : Lenovo_D
    
    DeviceID     : E:
    DriveType    : 3
    ProviderName :
    FreeSpace    : 164542201856
    Size         : 775692480512
    VolumeName   : Lenovo_E
    
    DeviceID     : F:
    DriveType    : 3
    ProviderName :
    FreeSpace    : 323696320512
    Size         : 438136991744
    VolumeName   : Lenovo_F
    
    DeviceID     : G:
    DriveType    : 3
    ProviderName :
    FreeSpace    : 383690104832
    Size         : 999750103040
    VolumeName   : Lenovo_G
    
    DeviceID     : H:
    DriveType    : 3
    ProviderName :
    FreeSpace    : 450752081920
    Size         : 1000631955456
    VolumeName   : Lenovo_H
    
    DeviceID     : J:
    DriveType    : 2
    ProviderName :
    FreeSpace    :
    Size         :
    VolumeName   :
    Even better is wmic:

    Code:
    PS C:\WINDOWS\system32> wmic diskdrive get deviceid,name,model,serialnumber,size,description
    Description  DeviceID            Model                         Name                SerialNumber     Size
    Disk drive   \\.\PHYSICALDRIVE0  Samsung SSD 860 EVO 500GB     \\.\PHYSICALDRIVE0  S3Z1NB0K412150T  500105249280
    Disk drive   \\.\PHYSICALDRIVE1  ST2000NM0011                  \\.\PHYSICALDRIVE1  Z1P3P2EB         2000396321280
    Disk drive   \\.\PHYSICALDRIVE3  Brother MFC-J615W USB Device  \\.\PHYSICALDRIVE3  BROG1F314697
    Disk drive   \\.\PHYSICALDRIVE2  ST2000DM006-2DM164            \\.\PHYSICALDRIVE2  Z4ZBZ9BB         2000396321280
      My ComputersSystem Spec


  7. Compumind's Avatar
    Posts : 1,308
    Windows 10 Pro x64, Various Linux Builds, Internet Security Specialty.
       #17

    @Ztruker -

    Thanks for helping out, Rich.

    Maybe this can be of help?

    c - How to list physical disks? - Stack Overflow

      My ComputerSystem Spec


  8. Posts : 48
    Windows 10 x64 1809
    Thread Starter
       #18

    Do you have any optical drives in your Lenovo? I've noticed that neither wmic nor powershell detect optical drives (at least using the commands I've discovered). For that matter, neither does disk part. Of course, that makes sense, they are working with physical drives and I need to work with removable drives as well.

    I'm going to do a clean install on m Test PC shortly and see how the drives look after that.
      My ComputerSystem Spec

  9. Ztruker's Avatar
    Posts : 8,817
    Windows 10 Pro X64 1903 18362.295
       #19

    I have a DVD R/W drive but it didn't have a disc in it.

    This at least shows the drive exists (J:) and is DriveType 2
    Code:
    C:\Users\ztruk>wmic logicaldisk list brief
    DeviceID  DriveType  FreeSpace     ProviderName  Size           VolumeName
    C:        3          187072557056                448944750592   Lenovo_C
    D:        3          690810855424                786567241728   Lenovo_D
    E:        3          164542160896                775692480512   Lenovo_E
    F:        3          323696320512                438136991744   Lenovo_F
    G:        3          382541590528                999750103040   Lenovo_G
    H:        3          450752081920                1000631955456  Lenovo_H
    J:        2
    0 = Unknown
    1 = No Root Directory
    2 = Removable Disk
    3 = Local Disk
    4 = Network Drive
    5 = Compact Disc
    6 = RAM Disk
      My ComputersSystem Spec


  10. Posts : 48
    Windows 10 x64 1809
    Thread Starter
       #20

    I found that wmic returned my USB drive as type 2 and the optical drives as type 5. That's all good.

    I added and removed drives and swapped drives to different ports in my test pc yesterday to see how that affects how windows detected and reported them. I've built up a table of the 10 PCs.

    The code is going to be somewhat convoluted, and won't be elegant (or probably the most efficient), but I think I'm going to be able to make it work.

    Will let you know how I go.
      My ComputerSystem Spec


 
Page 2 of 3 FirstFirst 123 LastLast

Related Threads
Solved Optical drive will not install in Drivers and Hardware
Toshiba Satellite laptop. New problem in the last few days. Windows 10 version 1809. Trying to send backup data to a flash drive, I noticed that the flash drive was labeled as 'D' instead of 'E' . Went to device manager, cd/dvd drive and saw this...
i just reinstalled windows and on my old install i had all my user profiles go to the e drive and not the c on this new install i want to do the same thing however i cannot rename the old user directory to users-old as it will cause explorer.exe...
Hi all, I'm sure this question has been asked multiple times, but it seems this forum is active, so hopefully someone can help me! I just ordered Windows 10 off newegg.com for a custom gaming PC i'm building. I'm not sure if its coming as a...
Solved Automating Password sign in in User Accounts and Family Safety
Using the "Netplwiz" in the Run box, I was able to automate the sign in password upon initially booting up my machine. When I first start up my machine, it immediately goes to my desktop without asking for the password. So far, so good. But when...
So I went to Microcenter and bought a Windows 10 Pro OEM version and it won't load at all on optical player. I have secure boot disabled and the keys are not installed either. For troubleshooting I have tried to use a different computer with a...
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 12:44.
Find Us