Bat file to echo list of computers

Posted on 2011-10-24
Last Modified: 2012-08-13
I am trying to make a bat file that will list all the computers turned on in my building.   They are all part of the same domain.  I can create the list but I am also trying to format the list so that only the computer names show up, one name on each line with no spaces.  I used the command "net view" to list all the computers turned on, on the domain. Then I use the find command to list only the computers I am looking for.  Then I need to remove all the "\\"  and all the white spaces.  Can you help me with this?  Im using windows 7 computers.  
net view > x.txt
find /I "CRL" x.txt > z.txt

Open in new window

Question by:ForLoop5
    LVL 3

    Expert Comment

    There is a command line utilty called bsed.exe that works very much like sed in unix.  It will allow you to search and replace.

    LVL 51

    Accepted Solution

    Here's a small BAT script that should do the job:

    @echo off
    setlocal EnableDelayedExpansion
    if exist "z.txt" del "z.txt"
    for /F "tokens=1" %%A in ('net view ^|find /I "CRL"') do (
      set PC=%%A
      echo !PC:\\=!>>"z.txt"

    Open in new window

    LVL 1

    Author Closing Comment

    That worked great.  Thank you!
    LVL 51

    Expert Comment

    by:Bill Prew
    Very welcome, glad that helped.


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    So many times I have seen the words written in a question "if only I could show you" or " I know how hard it is for you since you can't see it" in any zone. That has inspired me to write about this tool in windows 7 called "Problem Steps Recorder…
    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
    The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

    755 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

    24 Experts available now in Live!

    Get 1:1 Help Now