• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

Script to list hostnames with a pipe symbol to separate


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


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

1 Solution
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
No clue what you are talking about ;-) What is input and output?
tobe1424Author Commented:
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..


I want the output to be this


thanks in advance

tobe1424Author Commented:
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
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

Justin YeungSenior Systems EngineerCommented:
Get-Content c:\name.txt | % {$All += $_ + " | "}

Open in new window

The result will be "Host1 | Host2 | Host3 | Host4 |"
I think the input file is excel.
Instead of 4 per your example, you want one long string of 500?
tobe1424Author Commented:
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
tobe1424Author Commented:
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


Justin YeungSenior Systems EngineerCommented:
no problem and happy new year
tobe1424Author Commented:
likewise J !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now