1

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?

0

1 Answer 1

1

psftp must not be writing things to the standard output stream which is all that out-null operates on.

You can try redirecting all possible streams to the standard output stream using *>&1. For example:

Write-host "You can't see me" *>&1 | Out-Null

Or in your case:

$cmd | & $path_to_PSFTP -l $user -pw $password $IP_addr_of_switch *>&1 | Out-Null
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.