Solved

Script to list hostnames with a pipe symbol to separate

Posted on 2014-12-26
9
171 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
9 Comments
 
LVL 68

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
 
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 23

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
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…

947 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

18 Experts available now in Live!

Get 1:1 Help Now