I have one package on my Windows machine and another package on a remote server.
The first one is -> C:\Users\One . It contains the following files:
adapter.jsx
result.js
system.jsx
moment.js
readme.txt
info
that contains two files -> logger.jsx
and date.js
. Another one is a remote target directory -> /mnt/media/Two . It is currently empty. The user and host for it are: $userAndHost = "user@foo.bar"
I want to copy all the packages and files of extensions .jsx
and .js
from package One to package Two. It's required to use scp here since this is a copy between two different platforms .
What I tried:
Get-ChildItem -Path "C:\Users\One" -Recurse
.jsx
and .js
: Get-ChildItem -Path "C:\Users\One" -Recurse | Where-Object {$_.extension -in ".js",".jsx"}
Please, help me finish the script.
Hi i think you need something like this.
I write a code for you, tested working.
#Set execution policy to bypass
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
#install Posh-SSH from powershell gallery
#https://www.powershellgallery.com/packages/Posh-SSH/2.0.2
Install-Module -Name Posh-SSH -RequiredVersion 2.0.2
#import module
Import-Module Posh-SSH
#get all the items within the package in the path:
$path = 'C:\Users\One'
$items = (Get-ChildItem -Path $path -Name -File -Include ( '*.jsx', '*.js') -Recurse)
#Need destination credential
$credential = Get-Credential
#copy selected items to destination via scp
$items | ForEach-Object {
Set-SCPFile -ComputerName 'SCP-SERVER-HOST-HERE' -Credential $credential -RemotePath '/mnt/media/Two' -LocalFile "$path\$_"
}
Hope this helps you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.