123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- # Set configuration variables
- $remote_directory = "/data2/backups/bethany/{0}/Profiles/" -f ( $env:COMPUTERNAME )
- $local_directory = "c:\Users"
- $excludes = @(
- "*/Users/Default*/",
- "*/Users/All Users/",
- "*/Users/desktop.ini",
- "*/AppData/"
- )
- $transfermask = "| " + ($excludes -join ";")
- # Load WinSCP .NET assembly
- Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
- # Set up session options
- $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
- Protocol = [WinSCP.Protocol]::Sftp
- HostName = "gandalf"
- UserName = "bethany"
- Password = "haze7pie"
- SshHostKeyFingerprint = "ssh-ed25519 256 55:2d:b5:25:58:19:5d:cd:14:39:36:ec:c9:7c:ee:08"
- }
- $session = New-Object WinSCP.Session
- try
- {
- # Connect
- $session.Open($sessionOptions)
- # Your code
- $transferOptions = New-Object WinSCP.TransferOptions
- $transferOptions.TransferMode = [WinSCP.TransferMode]::Automatic
- $transferOptions.FileMask = $transfermask
- $transferOptions.FilePermissions = [WinSCP.FilePermissions](432)
- # Synchronize files
- $synchronizationResult = $session.SynchronizeDirectories(
- [WinSCP.SynchronizationMode]::Remote,
- $local_directory,
- $remote_directory,
- $True, #removeFiles
- $True, #mirror
- $transferOptions)
- # Throw on any error
- $synchronizationResult.Check()
- }
- finally
- {
- $session.Dispose()
- }
|