Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 从SFTP目录获取所有文件,扩展名为的子目录不工作。_Powershell_Powershell 3.0 - Fatal编程技术网

Powershell 从SFTP目录获取所有文件,扩展名为的子目录不工作。

Powershell 从SFTP目录获取所有文件,扩展名为的子目录不工作。,powershell,powershell-3.0,Powershell,Powershell 3.0,我使用下面的代码来获取文件,它对目录有效,但我也希望遍历子目录,当我放置-递归时,它停止工作 Import-Module –Name "C:\Users\Administrator\Documents\WindowsPowerShell\Modules\Posh-SSH" -Verbose $passwordTest = "Password" $securePasswordTest = ConvertTo-SecureString $passwordTest -AsPlainText -For

我使用下面的代码来获取文件,它对目录有效,但我也希望遍历子目录,当我放置-递归时,它停止工作

Import-Module –Name "C:\Users\Administrator\Documents\WindowsPowerShell\Modules\Posh-SSH" -Verbose

$passwordTest = "Password"
$securePasswordTest = ConvertTo-SecureString $passwordTest -AsPlainText -Force
$credentialsTest = New-Object System.Management.Automation.PSCredential ("USername", $securePasswordTest)
$sessionTest = New-SFTPSession -ComputerName SFTP -Credential $credentialsTest -AcceptKey
$sourceTest = "/u01/G"
$destinationTest= "F:\SourceOLTP\"

Get-SFTPChildItem $sessionTest -Path $sourceTest | ForEach-Object{
    if ($_.Fullname -like '*.csv') 
    {  
        Get-SFTPFile $sessionTest -RemoteFile $_.FullName -LocalPath $destinationTest -Overwrite 
    }

    write-output $_.FullName 

}


Remove-SFTPSession $sessionTest -Verbose

Get SFTPChildItem
上的递归开关似乎是
-Recursive


来源:

谢谢你的建议,但当我应用递归时,它会给我一个错误。Get-SFTPChildItem:找不到与参数名称“Recursive”匹配的参数。但是当您执行
-递归时,该错误不会出现?当您使用
-Recurse
时,它以什么方式停止工作?当我使用-Recurse时,它给出了不同的错误。找不到接受argumentTry
Get-SFTPChildItem-SFTPSession$sessionTest-Path$sourceTest-Recurse |…