Solved

Script to list hostnames with a pipe symbol to separate

Posted on 2014-12-26
9
177 Views
Last Modified: 2014-12-27
Hello,

I have a list of about 500 servers in an excel spreadsheet that I need to enter into a particular format:

[host::(hostname1|hostname2|hostname3|hostname4)]


I don't want to enter the 500 server names manually followed by a pipe several hundred times..

Is there a way I can parse the list of server names so that it outputs like BWICTXD01|BWIZDCD01|BWILICD01)]

Thanks much

t
0
Comment
Question by:tobe1424
[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
9 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 40519082
No clue what you are talking about ;-) What is input and output?
0
 

Author Comment

by:tobe1424
ID: 40519142
please excuse my lack of programming knowledge..

I have a list of 500 servers. As an example I am only using four.

the input would be a simple list..txt...docx..

host1
host2
host3
host4


I want the output to be this

(host1|host2|host3|host4)


thanks in advance

t
0
 

Author Comment

by:tobe1424
ID: 40519159
the output may also go into a txt file.

It sounds simple. But being a newb programmer, this is currently over the top of my head
0
IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 40519164
Get-Content c:\name.txt | % {$All += $_ + " | "}
$All

Open in new window


The result will be "Host1 | Host2 | Host3 | Host4 |"
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40519166
I think the input file is excel.
Instead of 4 per your example, you want one long string of 500?
0
 

Author Comment

by:tobe1424
ID: 40519189
Thanks Justin. I will give that a try right away.

NewVillage, Yes the file is in excel, but I can transfer the entire column to text only on a word/txt file which i will try to point to per justins instructions
0
 

Author Comment

by:tobe1424
ID: 40519220
Thanks a bunch justin !!! that worked flawlessly.

i had an issues executing the .ps1

cannot be loaded because the execution of scripts is disabled on this system.

But i ran this below and all worked fine afterwards

I have ran set-executionpolicy unrestricted

cheers

t
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40519230
no problem and happy new year
0
 

Author Comment

by:tobe1424
ID: 40519685
likewise J !
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

628 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