Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8416495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:46:28+00:00 2026-06-10T01:46:28+00:00

I need to create a powershell script that reads in two text files with

  • 0

I need to create a powershell script that reads in two text files with lists.
The first list is used to identify the remote computers that will have a file appended to it.
The second list is the key phrase that needs to be appended to the file.

List 1:
Computer1
Computer2
Computer3

List 2:
ABC
DEF
GHI

Script would loop through each pointing to a file say C:\temp\help.txt on each of the remote computers and write 1 line from List 2.

So Example: When the script runs it goes out to List 1, finds that computer 1 is first and opens the file \computer1\C$\temp\help.txt, it would then grab the first line from List 2 and write to the file ABC. Close the file and go on to Computer 2. Computer 2 would be \computer2\C$\temp\help.txt and would grab the 2nd item from List 2 and write to it DEF save and move on.

It’s been hard to find any help reading in and looping through 2 lists. Or perhaps I am thinking of it wrong. I have gotten to Get-Content to read in the file and foreach($x for text1) can go through 1 of the text files loops but can not figure out how to loop through the 2nd text file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:46:30+00:00Added an answer on June 10, 2026 at 1:46 am

    Processing side-by-side arrays is always a pain, and tends to be error prone. Ideally, as suggested, the computer names and strings would be together in a CSV or something.

    But as is, something like this should get you on the right track. You might have to fiddle with newlines at the beginning/end of the strings a bit.

    $machines = Get-Content .\MachineList.txt
    $strings = Get-Content .\StringsList.txt
    
    if($machines.Count -ne $strings.Count){ throw 'Counts do not match' }
    
    for($i = 0; $i -lt $strings.Count; $i++)
    {
      $path = "\\$($machines[$i])\C`$\temp\help.txt"   # unc path
      $strings[$i] | Add-Content $path
    }
    

    If you have it in a CSV like

    Config.csv
    ---------
    ComputerName,String
    machine1,string1
    machine2,string2
    machine3,string3
    

    Then you could simplify to this:

    Import-Csv .\Config.csv |%{
      $_.String | Add-Content "\\$($_.ComputerName)\C`$\temp\help.txt"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a Powershell script that sets some user attributes in Active
I currently have a PowerShell script that is used for complex automated Exchange mailbox
I have a Powershell script that uses System.Net.HttpWebRequest to communicate with a remote host.
I'm in need a script, in PowerShell or batch script, that will do the
I am trying to create a PowerShell script that creates a new IIS 6
I'm writing a PowerShell script that uses the SharePoint 2010 New-SPWeb cmdlet to create
I created a powershell script that gets all the pdb files from the drop
i need create an email list sending to many emails. what is best solution
I need to create a class with two properties: LogOutput ExceptionOutput These properties (Actions<>)
I have created a PowerShell script for copying files to a directory, the script,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.