title: Does Posh-ssh not work with windows Task Scheduler
body: <p>Been trying to connect to an sftp using posh-ssh. Works fine when i run it, when i try running it through windows task scheduler it does not work.</p>
  
  <p>I have tried switching around the users that are to run the script such as Admin, myself, system, etc.</p>
  
  <p>I have tried using keys to save the password and decrypt it later on.</p>
  
  <pre><code>$Password = ConvertTo-SecureString 'sftpPW' -AsPlainText -Force
  $Credential = New-Object System.Management.Automation.PSCredential($SFTPUser, $Password) 
  $sftpIP = 'hostIP'
  $sftpSess = New-SFTPSession -ComputerName $SftpIp -Credential $Credential
  </code></pre>
  
  <p>And then other method
  VVVVVVVVVV
  this part is run not in the script but is to create a password</p>
  
  <pre><code>Get-Random -Count 32 -InputObject (0..255) | Out-File -FilePath encrypt
  ConvertTo-SecureString 'sftpPW' -AsPlainText -Force | convertFrom-secureString -key (get-content -path encrypt) | Out-File pw
  </code></pre>
  
  <p>^^^^^^^^^^</p>
  
  <pre><code>$SFTPUser="user"
  $password = (cat pw | ConvertTo-SecureString -key (Get-Content -path encrypt))
  $Credential = New-Object System.Management.Automation.PSCredential($SFTPUser, $Password) 
  $sftpIP = 'hostIP'
  $sftpSess = New-SFTPSession -ComputerName $SftpIp -Credential $Credential
  </code></pre>
  
  <p>edit*</p>
  
  <pre><code>Import-Module Posh-SSH
  $datestuff = Get-Date
  echo "start $datestuff" &gt; C:\sftptestlog
  $SFTPUser="user"
  echo $sftpuser &gt;&gt; C:\sftptestlog
  $Password = ConvertTo-SecureString 'sftpPW' -AsPlainText -Force
  echo $password &gt;&gt; C:\sftptestlog
  $Credential = New-Object System.Management.Automation.PSCredential($SFTPUser, $Password) 
  $sftpIP = 'hostip'
  
  echo $Credential &gt;&gt; C:\sftptestlog
  echo $sftpip &gt;&gt; C:\sftptestlog
  $sftpSess = New-SFTPSession -ComputerName $SftpIp -Credential $Credential
  echo $sftpSess &gt;&gt; C:\sftptestlog
  
  </code></pre>
  
  <p>expected output from sftptestlog</p>
  
  <p>start 09/10/2019 16:31:19</p>
  
  <p>user</p>
  
  <p>System.Security.SecureString</p>
  
  <p>UserName                                               Password</p>
  
  <p>--------                                                                             --------</p>
  
  <p>user                                                            System.Security.SecureString</p>
  
  <p>hostIP</p>
  
  <p>SessionId  Host                                         Connected   </p>
  
  <p>---------  ----                                         ---------<br>
      2      hostIP                                  True            </p>
  
  <p>above output only happens when the script is run from the command line. When using scheduler the output is the same only the last lines (starting from sessionID) are not printed out.                 </p>