Modifying script to accept input from Text file?

Hi People,

I need to ask your help in modifying the script below so that it can take input from a list of servers from a text file.

like:

Get-Content -Path C:\Temp\computers.txt | ForEach-Object {
$computerName = $_
Write-Host "Processing $($computerName)"

# insert the code from https://www.powershelladmin.com/wiki/Get_Linux_disk_space_report_in_PowerShell

} | Export-Csv -Path C:\Temp\Freespace.csv
Get-SshSession | Select -Exp ComputerName | 
    %{ $c = $_; ConvertFrom-LinuxDfOutput -Text (Invoke-SshCommand -Comp $_ -Command 'df --portability' -q) } |
    Select @{n='ComputerName';e={$c}}, * | ft -AutoSize

Note: this is from: https://www.powershelladmin.com/wiki/Get_Linux_disk_space_report_in_PowerShell

 

Thank you in advance.

 

Are you asking for help or asking for someone to do it for you? What issues are you running into when attempting to configure it to take input?

@IT Engineer, If I understand what you are asking for, this is how I utilize data from a text file and output to a CSV.

$computerName = Get-Content 'C:\Temp\computers.txt' 
   $t = ForEach ($computer in $computerName) {
        Invoke-Command -ComputerName $computer {
               #insert the code from https://www.powershelladmin.com/wiki/Get_Linux_disk_space_report_in_PowerShell
                  }
       Write-Host "Processing $computer"

} 

$t | Export-Csv "C:\Temp\Freespace.csv"