Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: New Line

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default New Line

    I'm trying to write a batch script that I will run on users devices at logon via Group Policies.

    The objective is to get the following information logged and once I have this we will go ahead and put it into a database so we have everything updated and easily tracked. If I can get this working properly, it will save us ALOT of time because we have 400+ devices.

    The information I need to get is:
    Username - User that is currently logged in
    Device name
    Device Model
    Device Serial #
    Deploy date
    Ghost name - not sure how I will get this, but each device has a ghost number assigned to them to use if we need to remotely image the device.
    Wired Mac Address\Physical Address
    Wireless Mac Address\ Physical Address

    Here is what I currently have:
    PHP Code:
    @echo off

    ::Get Device Name
    echo Computer Type: >> "\\earth\tablets\james\Test.txt"
    wmic csproduct get name >> "\\earth\tablets\james\Test.txt"

    ::Get Device Serial Number
    echo Computer Serial Number: >> "\\earth\tablets\james\Test.txt"
    wmic bios get serialnumber >> "\\earth\tablets\james\Test.txt"

    ::Date
    date 
    />> "\\earth\tablets\james\Test.txt"

    ::Time
    time 
    />> "\\earth\tablets\james\Test.txt"

    ::Get Mac Addresses
    getmac 
    /fo list />> "\\earth\tablets\james\Test.txt"

    ::Username
    echo Username: %username%

    ::
    Computer name
    echo Hostname: >> "\\earth\tablets\james\Test.txt"
    hostname >> "\\earth\tablets\james\Test.txt"

    pause 
    Now for my questions.

    1. Is there a way to print newlines in between each output? When I am executing this on 400 devices, I don't want everything bunched up and hard to read so I want to format the text so it's easy to follow. Would be nice to adjust spacing as well as format it in columns if possible.

    2. It would be even better if it's possible to input the text info into a spreadsheet so then I can easily import it into an access db. This is optional, but would be helpful.

    3. The WMIC commands input additional "stuff" that's really unnecessary. Can I just output the following in red:

    Description Name
    Computer System Product HP Compaq dc7700 Ultra-slim Desktop
    Description SerialNumber
    Default System BIOS 2UA7310JPM

    4. With Getmac it outputs more stuff than necessary.
    I would officially like it to output something like this

    Lan: 00:12:34:56:78:90 or 00-12-34-56-78-90
    WLan: AA:BB:CCD:EE:FF or AA-BB-CC-DD-EE-FF

    I would appreciate any suggestions. Thanks!

  2. #2
    Administrator JoTo's Avatar
    Join Date
    May 2010
    Location
    www.scapp.net
    Posts
    1,953

    Default

    my suggestion: don't mess with bat files, go .Net
    Gamers Network - www.scapp.net

  3. #3
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Hmm not too familiar with .net eek I know.
    The reason I'm trying to stick with scripting (doesn't have to be .bat, .cmd necessarily, but I'm more familiar with those than vbs) is because In group policies it can easily be pushed out. I'm not sure how well it would work out with exe extensions.

    If I'm going to go the programming method, I will probably stick to c or c++, but it just seems it's more work than necessary to just pull simple computer related info like this argh. The nice thing about scripting is you can do it all with single lines of code, but it's messy errr.

  4. #4

    Default

    if I understood you right:

    a new line:
    echo.

    I think you can make a table with some weird characters but putting a tab between words is easier

    access db supports csv files right? So whether you use a semicolon or a comma for a csv file, you should be able to make a file like this:
    echo name;HP>>output.csv
    :)

  5. #5
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Updated my script to this and it seems to be working nicely.

    PHP Code:
    @echo off

    ::------------------------
    ::    Global 
    Variables
    ::------------------------

    setlocal enabledelayedexpansion
    set lineA
    =1
    set lineB
    =1
    set lineC
    =1
    set computername 
    hostname
    set date 
    date /t
    set time 
    time /t

    ::------------------------
    ::    
    User Name
    ::------------------------

    echo 
    The user name is: %username%

    ::------------------------
    ::    
    Device Name
    ::------------------------

    echo 
    The Device Name is: %computername%

    ::------------------------
    ::    
    Get Serial Number
    ::------------------------

    for /
    "delims=" %%A in ('wmic bios get serialnumber') do (
        if !
    lineAequ 2 set serialNumber=%%A
            set 
    /a lineA+=1)

    echo 
    The serial number is: %serialNumber%

    ::------------------------
    ::    
    Get Model
    ::------------------------

    for /
    "delims=" %%A in ('wmic csproduct get name') do (
        if !
    lineBequ 2 set modelName=%%A
            set 
    /a lineB+=1)

    echo 
    The computer model is: %modelName%

    ::------------------------
    ::    
    Deploy Date
    ::------------------------

    echo 
    The date and time the device got deployed is: %date% %time%

    ::------------------------
    ::    
    Get Mac Address
    ::------------------------

    for /
    "delims=" %%A in ('ipconfig/all ^| find "Physical Address"') do (
        for /
    "tokens=2-7 delims=:-" %%B in ("%%A") do ( 
            if 
    "%%C" NEQ "00" echo The mac address is:%%B-%%C-%%D-%%E-%%F-%%
        



    pause 

  6. #6
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Hey Possimos, quick question. Any way to setup the csv so the categories are across the top in columns as opposed to in rows in the first column?

  7. #7

    Default

    you mean like:

    Code:
    echo name;device name;serial>>output.csv
    echo %username%;%computername%;%serialNumber%>>output.csv
    or do it like this
    Code:
    set stringcat=name
    set stringcat=%stringcat%;device name
    set stringcat=%stringcat%;serial
    set stringval=%name%
    set stringval=%stringval%;%computername%
    set stringval=%stringval%;%serialNumber%
    
    echo %stringcat%>>output.csv
    echo %stringval%>>output.csv
    Last edited by Possimos; June 21st, 2011 at 09:57 AM. Reason: layout
    :)

  8. #8
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Hmm, it's outputting in 1 column now.


    The below would all be in column A

    name;device name;serial
    jkulikowski;JKULIKOWSKI;


    I'm sure you know what I'm after, but it would be something like

    Name Computer Name serial
    James jkulikowski 123456789

    Errr, I can't get it to display correctly.


    NVM, got it. Thanks. BTW it's not semicolons it's just commas.

  9. #9

    Default

    oh sorry that depends on the region that you live
    :)

  10. #10
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    No problem. Actually, perhaps you can look over my script, but it's not printing everything correctly.

    The mac address field is printing up as "%B-%C-%D-%E-%F-%G"
    and the wmic commands aren't coming out. The categories aren't printing either errr.

    Here is the script

    PHP Code:
    @echo off

    ::------------------------
    ::    Global 
    Variables
    ::------------------------

    setlocal enabledelayedexpansion
    set lineA 
    1
    set lineB 
    1
    set lineC 
    1
    set computername 
    hostname
    set date 
    date /t
    set time 
    time /t

    set stringcat 
    name
    set stringcat 
    = %stringcat%,User Name
    set stringcat 
    = %stringcat%,Device Name
    set stringcat 
    = %stringcat%,Serial Number
    set stringcat 
    = %stringcat%,Computer Model
    set stringcat 
    = %stringcat%,Deploy Date
    set stringcat 
    = %stringcat%,Wired Mac Address
    set stringcat 
    = %stringcat%,Wired Mac Address

    set stringval
    =%name%

    ::------------------------
    ::    
    User Name
    ::------------------------

    ::
    set stringval = %stringval%,%username%
    echo 
    Username,%username% >> \\earth\tablets\james\Test.csv

    ::------------------------
    ::    
    Device Name
    ::------------------------

    ::
    set stringval = %stringval%,%computername%
    echo 
    Computer Name,%computername% >> \\earth\tablets\james\Test.csv

    ::------------------------
    ::    
    Get Serial Number
    ::------------------------

    for /
    "delims=" %%A in ('wmic bios get serialnumber') do (
        if !
    lineAequ 2 set serialNumber=%%A
            set 
    /a lineA+=1)

    ::
    set stringval = %stringval%,%serialNumber%
    echo 
    Serial Number,%serialNumber% >> \\earth\tablets\james\Test.csv

    ::------------------------
    ::    
    Get Model
    ::------------------------

    for /
    "delims=" %%A in ('wmic csproduct get name') do (
        if !
    lineBequ 2 set modelName=%%A
            set 
    /a lineB+=1)

    ::
    set stringval = %stringval%,%modelName%
    echo 
    Computer Model,%modelName% >> \\earth\tablets\james\Test.csv

    ::------------------------
    ::    
    Deploy Date
    ::------------------------

    ::
    set stringval = %stringval%,%date% %time%
    echo 
    Deploy Date,%date% %time% >> \\earth\tablets\james\Test.csv

    ::------------------------
    ::    
    Get Mac Address
    ::------------------------

    for /
    "delims=" %%A in ('ipconfig/all ^| find "Physical Address"') do (
        for /
    "tokens=2-7 delims=:-" %%B in ("%%A") do ( 
            if 
    "%%C" NEQ "00" set stringval = echo Mac Addresses,%%B-%%C-%%D-%%E-%%F-%%>> \\earth\tablets\james\Test.csv
        



    set stringval=%name%
    set stringval=%stringval%,%username%
    set stringval=%stringval%,%computername%
    set stringval=%stringval%,%serialNumber%
    set stringval=%stringval%,%modelName%
    set stringval=%stringval%,%date% %time%
    set stringval=%stringval%,%%B-%%C-%%D-%%E-%%F-%%G
    set stringval
    =%stringval%,%%B-%%C-%%D-%%E-%%F-%%G

    echo %stringcat%>>c:\test2.csv
    echo %stringval%>>c:\test2.csv

    pause 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •