Hi Amigos,
I am facing issue with invoke PowerShell activity, I have an script for PowerShell WinSCP to download the first 3 latest excel files to my local desktop and trying to run it in studio.
I have multiple methods to just run this still getting nothing.
Here are some Screenshots and the script. btw script is working fine in powershell IE.
I have kept the username, password, hostname empty just for the security purpose.
Screenshot:
Script:
# Import the WinSCP assembly
Add-Type -Path "C:\Users\Ice\Documents\WindowsPowerShell\Modules\WinSCP\6.1.1.0\lib\net40\WinSCPnet.dll"
# Create a new SessionOptions object
$sessionOptions = New-Object WinSCP.SessionOptions
# Configure the session options
$sessionOptions.Protocol = [WinSCP.Protocol]::Ftp
$sessionOptions.HostName = ++++
$sessionOptions.UserName = ++++
$sessionOptions.Password = +++++
# Create a new Session object
$session = New-Object WinSCP.Session
try {
# Connect to the FTP server
$session.Open($sessionOptions)
# Get the file list
$directoryInfo = $session.ListDirectory("/")
# Filter out directories and sort files by modification time
$files = $directoryInfo.Files | Where-Object { -Not $_.IsDirectory -and ($_.FullName -like "*.csv" -or $_.FullName -like "*.xls*" ) } | Sort-Object LastWriteTime -Descending
# Download the latest three files
$downloadDirectory = "C:\Users\Ice\Downloads\RPA\"
$latestFiles = $files | Select-Object -First 3
foreach ($file in $latestFiles) {
$session.GetFiles($file.FullName, $downloadDirectory).Check()
}
}
finally {
# Disconnect and clean up
$session.Dispose()
}