Issue
I have a text file that contains server names that I want added to another file that is stored on a Linux server. What command would I need use to have the content of one text file added to another file stored in Linux. The file in Linux should still retain any information already stored on it. The file is related to Puppet autosign.conf
. The script below is what I am using to read the csv file I have that contains a list of server names I need. The script essentially pulls the only the server names in a way I want them listed. I just now need the command to append my results onto the file in Linux.
$data =
Get-Content "C:\dev\Scripts\Admin Scripts\Environment Deployment\vms2deploy.csv" |
Select-Object -skip 1 |
ConvertFrom-Csv -header name
$myhosts = foreach ($item in $data) { Write-Output $item.name }
$myhosts >> 'c:\temp\host_list.txt'
Update:
Atfer reading the suggestion below i was struck with a thought and came up with these commands to run to solve my issue.
Set-SCPFile -ComputerName servername -Credential (Get-Credential) -LocalFile "c:\temp\host_list.txt" -RemotePath "/home/puppetmaster" Invoke-SSHCommand -Index 0 -Command "cat host_list.txt >> autosign.conf"
Doing this I was able to send my file up to the server and then have it appended to where i want it. The new issue is the autosign.conf seems to be binary and my text file is utf-16le. how would I change the text file to binary so when appended it wont have problems.
Solution
After reading the other answers, I was struck with a thought and came up with these commands to run to solve my issue.
Set-SCPFile -ComputerName servername -Credential (Get-Credential) -LocalFile "c:\temp\host_list.txt" -RemotePath "/home/puppetmaster"
Invoke-SSHCommand -Index 0 -Command "cat host_list.txt >> autosign.conf"
Doing this I was able to send my file up to the server and then have it appended to where i want it.
Answered By - athlonxl Answer Checked By - Terry (WPSolving Volunteer)