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.


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

# insert the code from

} | 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: Get Linux disk space report in PowerShell - Svendsen Tech


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
       Write-Host "Processing $computer"


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