Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Need to change a list of machine's label as i mention

Posted on 2007-08-10
Medium Priority
Last Modified: 2010-03-05

I have the machine names in a file.Need to change all the machines labels to what i mention.I should have a option as C: Label name D: Labelname  etc.

What i mention as labelname should be changed to all machines in the file.

Question by:bsharath
  • 4
  • 3
LVL 14

Expert Comment

ID: 19675325
' set-HD-label-all-PCs.vbs
' read the computer computers list from the file c:\computers.txt
' for set C e D HDlabel on file run:
' cscript //nologo set-HD-label-all-PCs.vbs >result.txt
' Gastone Canali
'*** modify with new HD label
labelCname="Drive C"
labelDname="Drive D"
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Computers.txt", ForReading)
do while not objFile.AtEndOfStream
    PC = objFile.ReadLine
    SEThdinfo (PC)
sub SEThdinfo(strComputer)
  On Error Resume Next
  Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/CIMV2" )
  Set colInstances = objWMIService.ExecQuery( "SELECT * FROM Win32_LogicalDisk where driveType=3",  "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )
  If Err.Number = 0 then
    For Each objInstance In colInstances
          getinfo=getinfo & " " & objInstance.deviceID &" " & objInstance.volumename
          if objInstance.deviceID="C:" then
             objInstance.VolumeName = labelCname
          end if
          if objInstance.deviceID="D:" then
             objInstance.VolumeName = labelDname
          end if
    getinfo="Error computer not found"
  end if
  WScript.echo strComputer & space(10-len(strComputer)) &": " & getinfo
end sub
LVL 11

Author Comment

ID: 19675455
File gets created but no output...
LVL 14

Expert Comment

ID: 19676045
Label are changed?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 11

Author Comment

ID: 19676233
Where should i mention the label name.

I checked no label names changed.

FYI.I have 3 or 4 drives in 1 machine
LVL 14

Expert Comment

ID: 19676309
the script change only C and D.

'*** modify with new HD label
labelCname="Drive C"
labelDname="Drive D"
LVL 11

Author Comment

ID: 19676338
I tried but no changes...
LVL 14

Accepted Solution

canali earned 2000 total points
ID: 19676690
: * To run this script you must have domain administrators rights.
:: * This script require "Computers.txt" file on C: drive root from where it will pick computer names.
:: * Successful run will generate "setlabel.log" on C: drive root.
:: * Copy and Paste following script into notepad and save it with any name having .bat  extension.
:: Batch Script Start

@Echo Off
SETLOCAL EnableDelayedExpansion
:: *** change here your hd label
:: * disk c: will have the label systemC
set c:="systemC"
:: * disk D: will have the label data D
set d:="data D"
:: * disk E: will have the label bsharathLAB
set e:="bsharathLAB"
:: * disk F: will have the label PAGE
set f:="PAGE"
:: *** if u have more disk add a line
:: *** like above Ex.: to change the label on disk j:
:: *** set j:="labelForJ"
IF NOT EXIST C:\Computers.txt Goto ShowErr
FOR %%R IN (C:\Computers.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\setlabel.log DEL /F /Q C:\setlabel.log

FOR /F %%c IN ('Type Computers.txt') Do (
    Echo Processing: %%c
      PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
      IF NOT ErrorLevel 1 (
            rem SET Qry=WMIC /NODE:"%%c" LOGICALDISK GET DeviceID,VolumeName ^| Find ":"
            SET Qry=WMIC /NODE:"%%c" LOGICALDISK where driveType=3 GET DeviceID,VolumeName ^| Find ":"
            SET SETlabel1=WMIC /NODE:"%%c" LOGICALDISK where deviceId^=
            SET SETlabel2= set VolumeName^=
            FOR /F "tokens=1-2" %%d IN ('!Qry!') DO  !SETlabel1!'%%d'!SETlabel2!!%%d! 2>nul >>c:\setlabel.log
      )ELSE (Echo %%c: Not able to connect >>C:\setlabel.log)

Goto EndScript
Echo "C:\Computers.txt" file does not exist or file is empty!
:: Batch Script End

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

My previous article  (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html)detailed one possible method to get SCCM 2007 installed an…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses

564 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