I have written a Powershell script that uses psftp.exe to back up config files from a number of switches. The guts of the psftp loop, adapted from here, are as follows:
# set up array of psftp commands to run on each switch
$cmd = @("get $config_file_on_switch $local_filename","quit")
#
# pipe those commands to a psftp call
$cmd | & $path_to_PSFTP -l $user -pw $password $IP_addr_of_switch
#
# this is all I'd really like to see on the Powershell console:
Write-Host $name_of_switch
This works fine -- the above code is inside a loop that traverses a CSV list of switch IP addresses, and it does what it should in terms of collecting config files. But I would like to suppress the responses of the switch to the psftp commands. psftp.exe has no mechanism for disabling console output, and trying to do it in Powershell by adding | Out-Null
at the end of the second line of code above does not suppress display of the switch output.
I should add that this problem occurs in the Powershell CLI window, not in the Powershell ISE console pane.
Any ideas on how to muzzle psftp in this script?