Options

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

# Topic review

martin

Are you sure this is a WinSCP question? I believe that the error indicates that your `get-psw` function does not work correctly in the ISE environment. What did you do to verify that the credentials are retrieved correctly?
Rick

`\$localPath  = "\\folder1\log"\$remotePath = "/folder1/LOG" # Load WinSCP .NET assemblyAdd-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" \$SId = 1 function get-psw{  param(    [String]\$SID  )  [Hashtable]\$return = @{}  #Get Username and Password  \$SS = ''  \$SSWS = New-WebServiceProxy -Uri \$SS -UseDefaultCredential  \$Secret = \$SSWS.GetSecret(\$SID, \$false, \$null)  \$psw = ((\$Secret.Secret.Items | Where-Object{ \$_.FieldDisplayName -eq 'Password' }).Value)  \$usr = ((\$Secret.Secret.Items | Where-Object{ \$_.FieldDisplayName -eq 'Username' }).Value)  if (!\$psw)  {    \$msg="Couldn't get credentials"    Write-Error -Message \$msg -ErrorAction Stop    exit 1  }return @{username=\$username;password=\$password}} try{       # Set up session options      \$sessionOptions = New-Object WinSCP.SessionOptions -Property @{      Protocol = [WinSCP.Protocol]::Ftp      HostName = ""        Username = \$usr        Password = \$psw      FtpSecure = [WinSCP.FtpSecure]::Explicit    }     \$session = New-Object WinSCP.Session    try    {        # Connect        \$session.Open(\$sessionOptions)         # Synchronize files        \$synchronizationResult = \$session.SynchronizeDirectories(            [WinSCP.SynchronizationMode]::Local, \$localPath, \$remotePath, \$False)         # Throw on any error        \$synchronizationResult.Check()    }    finally    {        # Disconnect, clean up        \$session.Dispose()    }     exit 0}catch{    Write-Host "Error: \$(\$_.Exception.Message)"    exit 1}`