Solved

MSDOS script needed : diskpart/s in one script & output to 'hstname'.txt

Posted on 2008-10-27
2
4,450 Views
Last Modified: 2012-06-27
Hi

I would like a .bat or .cmd script that do :
a) date/t >> hostname.txt
b) sc queryex >> hostname.txt
c) echo ==========  >> hostname.txt
d) diskpart/s  scriptname >> hostname.txt


where hostname is the server's hostname as obtained by the
command "hostname".  So if my server's hostname  is Atlanta,
then the output file is  Atlanta.txt

Also, "diskpart/s scriptname"  requires a separate file scriptname
& this separate file scriptname contains two lines :
LIST VOLUME
LIST DISK
SELECT DISK 0  
LIST PARTITION
SELECT DISK x  (other any other disks that are present)
LIST PARTITION
... repeat till all disks present have been selected one by one & partition listed ...

diskpart/s scriptname currently gives following output (as there's only 1 disk in my
current server but other servers may have more disks) :

Microsoft DiskPart version 5.1.3565
Copyright (C) 1999-2003 Microsoft Corporation.
On computer: CORE2
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D                       DVD-ROM         0 B
  Volume 1     E   Mobile Part  CDFS   CD-ROM      7168 KB
  Volume 2     C                NTFS   Partition     70 GB  Healthy    System

  Disk ###  Status      Size     Free     Dyn  Gpt
  --------  ----------  -------  -------  ---  ---
  Disk 0    Online        73 GB      0 B

Disk 0 is now the selected disk.

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    OEM                 47 MB    32 KB
  Partition 2    Primary             70 GB    47 MB
  Partition 3    Unknown           3075 MB    70 GB


Would like to incorporate the above 2 lines of codes into the parent
script so that there's only one file to copy to each server instead of
two files (one parent script & the scriptname file)
0
Comment
Question by:sunhux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:sunhux
ID: 22813235
If it's not possible to do it in one single script file (one .cmd or one .bat),
multiple files solution is acceptable too.

Just some corrections (indicated by *)  to my earlier typo to one paragraph above :

Also, "diskpart/s scriptname"  requires a separate file scriptname
& this separate file scriptname contains two lines :
LIST VOLUME
LIST DISK
SELECT DISK 0  
LIST PARTITION
SELECT DISK x  (* any other disks that are present)
LIST PARTITION
... repeat till all disks present have been selected &  partition listed*  ...
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22813449
Paste the script below into a text file with a .cmd extension.  Running it will create diskpart scripts on the fly and then delete them when done.  Output will be echoed to a text file named with the current computername.


@echo off
setlocal
 
set script1=%temp%\dpscript1.txt
set script2=%temp%\dpscript2.txt
set log=%computername%.txt
 
echo LIST DISK>"%script1%"
echo LIST VOLUME>"%script2%"
echo LIST DISK>>"%script2%"
 
for /F "tokens=2 skip=8" %%G in ('diskpart /s "%script1%"') do (
 echo SELECT DISK %%G>>"%script2%"
 echo LIST PARTITION>>"%script2%"
)
 
date /t>"%log%"
sc queryex>>"%log%"
echo ==========>>"%log%"
diskpart /s "%script2%">>"%log%"
 
del "%script1%"
del "%script2%"

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
network copying issue 4 72
batch script 3 56
Batch: reboot servers one by one. 4 38
VBS script  to map network printers to all users. 3 60
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question