Using Diskpart on a Server Core Remote Shell

AID: 7892
  • Status: Published

1050 points

  • ByMrGraves
  • TypeGeneral
  • Posted on2011-09-26 at 11:03:05

To effectively work with Diskpart on a Server Core, it is necessary to write some small batch script's, because you can't execute diskpart in a remote powershell session.

To get startet, place the Diskpart batch script's into a share on your local computer and mount it to your server core:

Limited access to the Server Core:

net use z: \\mycomputer\myshare /user:mydomian\myuser Test123 -> Dummy user recommended, cause you must add the password over remoteshell
                                    
1:

Select allOpen in new window


or

Full access to the Server Core:
Copy the files to the Servercore \\servercore\C$ share, using an administrative user.


How to use Diskpart and your scripts:
I allways have a basic "list" script to get an overview over the current situation:

rescan
List disk
List volume
Exit
                                    
1:
2:
3:
4:

Select allOpen in new window



And it's executed like this:

DISKPART /S c:\list
                                    
1:

Select allOpen in new window



You can give any/no filetype to the script (list.txt, list.cmd) you like.

Output example:

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online           74 GB      0 B
  Disk 1    Offline          74 GB      0 B

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D                       DVD-ROM         0 B  No Media
  Volume 1         System Rese  NTFS   Partition    100 MB  Healthy    System
  Volume 2     C                NTFS   Partition     74 GB  Healthy    Boot
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:

Select allOpen in new window




What's most important to find out is, if a dvd drive is mounted on the server core, cause this will change the volume numbers and you have to use a different script. Copy the examples to a file and execute them with DISKPART /S:

Warning! If a volume 2,3,or 4 is already existing on your server and its not the system volume it will be deleted! Try in a test evironment first please!

Example 1 (DVD = Volume 1):
This will set Disk 2 online, create a new Volume (3) on Disk 2, do a standard format of volume 3 and add the next free drive letter to it.

list disk 
select disk 2
online disk
attr disk clear readonly
create partition primary
list volume
select volume 3
format
select volume 3
ASSIGN
exit
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window




Example 2 (no DVD):
This will set Disk 2 online, create a new Volume (2) on Disk 2, do a Standard format of volume 2 and add the next free drive letter to it.

list disk 
select disk 2
online disk
attr disk clear readonly
create partition primary
list volume
select volume 2
format
select volume 2
ASSIGN
exit
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window




Example 3 (add second volume after Example 1):
This will set Disk 3 online, create a new Volume (4) on Disk 3, do a Standard format of volume 4 and add the next free drive letter to it.

list disk 
select disk 3
online disk
attr disk clear readonly
list volume
select volume 4
format
select volume 4
ASSIGN
exit
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window




I recommend you to work with DISKPART only! Powershell command's like get-psdrive won't rescan for new drive's and partitions you have added to the server! They will update only after a logging of your remote session and reconnecting to the Server core. To update the drives in Diskpart just execute the list script again and the RESCAN command will scan your server for new drives (yes, it's not really necessary , but it won't hurt).

Sometimes one or two of the last commands of the script's have not executed at all and I had to add a short script that will only execute the ASSIGN command for example. Maybe it's better to execute DISKPART on a large drives/volumes in a PowerShell backround job to avoid the permanent updating of your remoteshell when the format command ist executed.

I hope this was informative and good luck!

Asked On
2011-09-26 at 11:03:05ID7892
Tags

Diskpart

,

Microsoft

,

Server Core

,

Server 2008

,

Configuration

,

Remote Shell

Topic

Windows Server 2008

Views
432

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Loading Advertisement...

Top Windows Server 2008 Experts

  1. dariusg

    177,079

    Guru

    8,770 points yesterday

    Profile
    Rank: Genius
  2. demazter

    150,708

    Guru

    4,030 points yesterday

    Profile
    Rank: Genius
  3. kevinhsieh

    115,786

    Master

    0 points yesterday

    Profile
    Rank: Genius
  4. hanccocka

    89,826

    Master

    2,750 points yesterday

    Profile
    Rank: Genius
  5. mkline71

    69,230

    Master

    3,000 points yesterday

    Profile
    Rank: Genius
  6. leew

    63,966

    Master

    2,500 points yesterday

    Profile
    Rank: Savant
  7. newmath

    54,926

    Master

    0 points yesterday

    Profile
    Rank: Master
  8. alanhardisty

    48,296

    2,000 points yesterday

    Profile
    Rank: Genius
  9. dstewartjr

    39,268

    3,000 points yesterday

    Profile
    Rank: Genius
  10. arnold

    36,791

    0 points yesterday

    Profile
    Rank: Genius
  11. Mutawadi

    31,600

    2,000 points yesterday

    Profile
    Rank: Guru
  12. jordannet

    29,914

    0 points yesterday

    Profile
    Rank: Wizard
  13. ve3ofa

    29,626

    2,800 points yesterday

    Profile
    Rank: Genius
  14. LesterClayton

    28,114

    0 points yesterday

    Profile
    Rank: Guru
  15. dvt_localboy

    27,990

    1,000 points yesterday

    Profile
    Rank: Sage
  16. iSiek

    27,948

    0 points yesterday

    Profile
    Rank: Genius
  17. hhaywood000

    27,784

    0 points yesterday

    Profile
    Rank: Guru
  18. CarlWebster

    27,548

    0 points yesterday

    Profile
    Rank: Genius
  19. Neilsr

    26,570

    0 points yesterday

    Profile
    Rank: Genius
  20. radhakrishnan2007

    24,329

    0 points yesterday

    Profile
    Rank: Wizard
  21. dkotte

    24,160

    0 points yesterday

    Profile
    Rank: Guru
  22. Run5k

    23,392

    0 points yesterday

    Profile
    Rank: Genius
  23. spaperov

    20,900

    0 points yesterday

    Profile
    Rank: Wizard
  24. cwstad2

    20,489

    0 points yesterday

    Profile
    Rank: Master
  25. Murali1984

    20,410

    0 points yesterday

    Profile
    Rank: Guru

Hall Of Fame