I have a powershell script from PRTG that will ssh into a juniper device and allow me to exicute a command. I am trying to run "Request System Storage Cleanup" which works but the problem is the session asks for conformation of the clean up. Adding a carriage return and then yes in the same line does not work nor did adding another command. I cannot use "Request system storage cleanup no-confirm" due to the firmware is not new enough. Any suggestion on how to confirm the command?

    $Computername = "",
    $Username = "",
    $Password = "",
    $Port = 22,
    $KeyfilePath = "",
    $Command = ("request system storage cleanup"),
    $AutoUpdateFingerprint = $False

# Check if our module loaded properly
if (Get-Module -ListAvailable -Name Posh-SSH) { <# do nothing #> }
else { 
    # install the module automatically
    iex (New-Object Net.WebClient).DownloadString("https://gist.github.com/darkoperator/6152630/raw/c67de4f7cd780ba367cccbc2593f38d18ce6df89/instposhsshdev")

function This-FingerPrintUpdate(){
    { Remove-SSHTrustedHost $Computername }

# Includes
Import-Module Posh-SSH

function This-GetSSHCommandOutput(){
    # Create new session and execute the command given
    if($keyfilePath.Length -eq 0){

        # Generate credentials object for authentication
    $SecPasswd   = ConvertTo-SecureString $Password -AsPlainText -Force
    $Credentials = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd) 
    $Session = New-SSHSession -Computername $Computername -Credential $Credentials -Port $Port -Acceptkey

    { $Session = New-SSHSession -Computername $Computername -Acceptkey $true -KeyFile $keyfilePath -Port $Port }

    # Store the output of the command 
    $Output = (Invoke-SSHCommand -SSHSession $Session -Command $Command -PipelineVariable "yes").Output

    # Remove the session after we're done
    Remove-SSHSession -Name $Session | Out-Null 

    # return the actual output
    Write-Host $Output.Trim();


# Automatically update the fingerprint for the given host. 

# echo the output 
9 Months
Discussion Span
Last Post by rproffitt
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.