Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
Amazon web services 如何使用文件夹的最后修改日期将文件上载到S3?_Amazon Web Services_Powershell_Amazon S3_Amazon Ec2_Scripting - Fatal编程技术网

Amazon web services 如何使用文件夹的最后修改日期将文件上载到S3?

Amazon web services 如何使用文件夹的最后修改日期将文件上载到S3?,amazon-web-services,powershell,amazon-s3,amazon-ec2,scripting,Amazon Web Services,Powershell,Amazon S3,Amazon Ec2,Scripting,我正在尝试编写一个PowerShell脚本,允许我根据文件夹的最后修改日期将文件上载到AWS S3存储桶 这就是我迄今为止所做的: using namespace System.IO; Set-AWSCredentials -StoredCredentials MyCredentialsAws Set-DefaultAWSRegion us-east-1 [String] $root = "C:\Users\Administrator\Documents\TestFolder"; [Date

我正在尝试编写一个PowerShell脚本,允许我根据文件夹的最后修改日期将文件上载到AWS S3存储桶

这就是我迄今为止所做的:

using namespace System.IO;
Set-AWSCredentials -StoredCredentials MyCredentialsAws
Set-DefaultAWSRegion us-east-1

[String] $root = "C:\Users\Administrator\Documents\TestFolder";

[DateTime]$today = [DateTime]::Now.Date;

[FileSystemInfo[]]$folderList = Get-ChildItem -Path $root -Directory;
foreach( $folder in $folderList ) {

    if( $folder.LastWriteTime -lt $today ) {
        [String] $folderPath = $folder.FullName;
        aws s3 cp $folder s3://bucketname/$folder --recursive 
   }
}
但是,上面给出了一个错误:

“用户提供的路径不存在”


任何帮助都将不胜感激。

首先,当您可能打算使用
$folderPath
时,您在
aws
命令行中使用了
$folder
作为源代码。另外,
Get ChildItem
的扩展也不一致。根据上下文的不同,对象有时只扩展到名称,有时扩展到完整路径(以获得更详细的解释)。因此,明确使用给定场景所需的属性(
Name
FullName
,…)被认为是良好的做法


该消息看起来像来自aws的
aws
命令。试试
$name=$folder.name;aws s3 cp$folderPath s3://bucketname/$name--recursive
。修复了它!!!你是上帝的伴侣@AnsgarWiechers
if ($folder.LastWriteTime -lt $today) {
    $folderPath = $folder.FullName
    $folderName = $folder.Name
    aws s3 cp $folderPath s3://bucketname/$folderName --recursive 
}