Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #WinSCP Synchronize
- $Path = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WinSCP"
- If (Test-Path $Path) {
- Write-Host "WinSCP PoSh module installed, loading it"
- Import-Module WinSCP
- Write-Host "WinSCP Module Loaded"
- }
- Else {
- Write-Host "WinSCP PoSh module not installed, installing it"
- & ((Split-Path $MyInvocation.InvocationName) + "\Install WinSCP Powershell Module.ps1")
- Import-Module WinSCP
- Write-Host "WinSCP Module Loaded"
- }
- $SMTP = "mail.domain.com"
- $From = "[email protected]"
- $To = "[email protected]"
- $CC = "[email protected]"
- $Date = Get-Date -format "MM.dd.yyy HH:mm"
- $LocalFolder = "\\UNPath\c$\FolderToSync"
- $RemoteFolder = "./"
- $sessionOptions = @{
- HostName = "ServerNameOrIP"
- UserName = "UserName"
- Password = "Password"
- SshHostKeyFingerprint = "SSH-RSA Key"
- }
- Try {
- Write-Host "Opening WinSCP session"
- $session = Open-WinSCPSession -SessionOptions (New-WinSCPSessionOptions @sessionOptions)
- Write-Host "Successfully connected, "
- Sync-WinSCPDirectory -WinSCPSession $session -RemotePath $RemoteFolder -LocalPath $LocalFolder -Mode Remote | Out-Null
- Send-MailMessage -SmtpServer $SMTP -From $From -To $To -Cc $CC -Subject "Results Sync Scheduled Task" -Body "Successfully synchronized results folder on $Date!"
- }
- Catch {
- Send-MailMessage -SmtpServer $SMTP -From $From -To $To -Cc $CC -Subject "Results Sync Scheduled Task" -Body "Failed to synchronize results folder on $Date!"
- }
Advertisement
Add Comment
Please, Sign In to add comment