Automating installation rename optical and SSD/HDD during post install

Page 2 of 3 FirstFirst 123 LastLast

  1. Posts : 14,046
    Windows 11 Pro X64 22H2 22621.1848
       #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 Computers


  2. Posts : 5,048
    Windows 10/11 Pro x64, Various Linux Builds, Networking, Storage, Cybersecurity Specialty.
       #12

    Wobitancrawfodi said:
    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 Computer


  3. Posts : 425
    Windows 10
    Thread Starter
       #13

    Ztruker said:
    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 Computer


  4. Posts : 14,046
    Windows 11 Pro X64 22H2 22621.1848
       #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 Computers


  5. Posts : 425
    Windows 10
    Thread Starter
       #15

    Ztruker said:
    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 Computer


  6. Posts : 14,046
    Windows 11 Pro X64 22H2 22621.1848
       #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 Computers


  7. Posts : 5,048
    Windows 10/11 Pro x64, Various Linux Builds, Networking, Storage, Cybersecurity Specialty.
       #17

    @Ztruker -

    Thanks for helping out, Rich.

    Maybe this can be of help?

    c - How to list physical disks? - Stack Overflow

      My Computer


  8. Posts : 425
    Windows 10
    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 Computer


  9. Posts : 14,046
    Windows 11 Pro X64 22H2 22621.1848
       #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 Computers


  10. Posts : 425
    Windows 10
    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 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 00:12.
Find Us




Windows 10 Forums