【发布时间】:2019-10-03 23:06:16
【问题描述】:
我正在尝试编写一个 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
}
}
但是,上面给了我错误:
“用户提供的路径不存在”
任何帮助将不胜感激。
【问题讨论】:
-
该消息看起来像是来自
aws命令。试试$name = $folder.Name; aws s3 cp $folderPath s3://bucketname/$name --recursive。 -
解决了!!!你是神队友@AnsgarWiechers
标签: amazon-web-services powershell amazon-s3 amazon-ec2 scripting