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

Posted on 2007-08-10
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
    LVL 14

    Expert Comment

    ' 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

    File gets created but no output...
    LVL 14

    Expert Comment

    Label are changed?
    LVL 11

    Author Comment

    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

    the script change only C and D.

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

    Author Comment

    I tried but no changes...
    LVL 14

    Accepted Solution

    : * 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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
    This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now