Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script to list hostnames with a pipe symbol to separate

Posted on 2014-12-26
9
Medium Priority
?
181 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 71

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
Lessons on Wi-Fi & Recommendations on KRACK

Simplicity and security can be a difficult  balance for any business to tackle. Join us on December 6th for a look at your company's biggest security gap. We will also address the most recent attack, "KRACK" and provide recommendations on how to secure your Wi-Fi network today!

 
LVL 14

Accepted Solution

by:
Justin Yeung earned 2000 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 25

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

927 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