none
Accessing WinSCP from an Azure Runbook RRS feed

  • Question

  • A powershell script that I run locally uses the WinSCP dll from the same directory.   But when I put that script into an Azure Runbook, I need to access WinSCP from there.   Do I need to install it on a cloud service to access it there?

    Locally I just use this line...

    Add-Type -Path "WinSCPnet.dll"

    Thanks!

    Monday, August 19, 2019 4:55 PM

All replies

  • Its only possible using Azure Hybrid Runbook Worker. First import the WinSCP module from Powershell Gallery to Azure Automation. Please make sure the required dll is available in the module.

    Then you can import assembly as shown below.

    $ErrorActionPreference="Stop"
    import-module WinSCP
    $assemblylist =   
    "WinSCPnet.dll" 
      
    foreach ($asm in $assemblylist)  
    {  
        $asm = [Reflection.Assembly]::LoadWithPartialName($asm)  
    }  
    Hope this helps!

    Tuesday, August 20, 2019 6:58 AM
    Moderator
  • Hi, 

    If you use a cloud based runbook worker you will have to either copy the DLL from a location to the temporary runbook worker harddisk or call the DLL file from the location it is stored. If you copy the DLL, make sure to copy it each time the runbook runs on a cloud based runbook worker. 


    Anders Bengtsson | Microsoft PFE | blog at http://www.contoso.se

    Tuesday, August 20, 2019 7:16 AM
  • Where would I copy it to?  
    Thursday, August 22, 2019 4:02 PM
  • I imported the dll and added that code after Add-Type -Path "WinSCPnet.dll"  and am getting this error...

    Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path 'C:\Temp\frjgdjet.yv4\WinSCPnet.dll' because it does not exist.

    It's still looking for the dll locally?  

    Thursday, August 22, 2019 9:57 PM
  • When you import dll , the modules get loaded in Azure Runbook in the folder "C:\Modules\User\WinSCPnet". To access the dll, you can below snippet.

    Get-ChildItem -Path C:\Modules\User\WinSCPnet -Force -Recurse
    
    #Loading WinSCPnet.dll type
    
    Add-Type -Path "C:\Modules\User\WinSCPnet\WinSCPnet.dll"

    Friday, August 23, 2019 5:02 AM
    Moderator
  • I'm getting this...

    Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path 'C:\Modules\User\WinSCPnet\WinSCPnet.dll' because it does not exist." (Exception setting "Path": "Cannot find path 'C:\Modules\User\WinSCPnet\WinSCPnet.dll' because it does not exist." (Cannot find path 'C:\Modules\User\WinSCPnet\WinSCPnet.dll' because it does not exist.))

    I just checked and it is there.   Any reason why it may not be found?

    • Edited by JohnBorges Friday, August 23, 2019 5:11 PM
    Friday, August 23, 2019 5:10 PM