Solved

Script to list hostnames with a pipe symbol to separate

Posted on 2014-12-26
9
170 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
Comment Utility
No clue what you are talking about ;-) What is input and output?
0
 

Author Comment

by:tobe1424
Comment Utility
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
Comment Utility
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
Comment Utility
Get-Content c:\name.txt | % {$All += $_ + " | "}
$All

Open in new window


The result will be "Host1 | Host2 | Host3 | Host4 |"
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 23

Expert Comment

by:NVIT
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
no problem and happy new year
0
 

Author Comment

by:tobe1424
Comment Utility
likewise J !
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
A procedure for exporting installed hotfix details of remote computers using powershell
The viewer will learn how to count occurrences of each item in an array.
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 …

762 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

9 Experts available now in Live!

Get 1:1 Help Now