Solved

Script to list hostnames with a pipe symbol to separate

Posted on 2014-12-26
9
176 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 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