我要求将7天之前的IIS日志上传到AWS S3 Bukcet.通过使用以下代码,我可以访问存储桶下的AWS文件夹
Import-Module "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1"
$AKey = ""
$SKey = ""
$source = "C:\inetpub\logs\LogFiles\*"
$outputpath = "C:\scripts\Logs\logs3.txt"
Set-AWSCredentials -AccessKey $AKey -SecretKey $SKey
function Get-Subdirectories {
param (
[string] $BucketName,
[string] $KeyPrefix,
[bool] $Recurse
)
@(Get-S3Object -BucketName $BucketName -KeyPrefix $KeyPrefix -Delimiter '/') | Out-Null
if ($AWSHistory.LastCommand.Responses.Last.CommonPrefixes.Count -eq 0) {
return
}
$AWSHistory.LastCommand.Responses.Last.CommonPrefixes
if ($Recurse) {
$AWSHistory.LastCommand.Responses.Last.CommonPrefixes | ForEach-Object { Get-Subdirectories -BucketName $BucketName -KeyPrefix $_ -Recurse $Recurse }
}
}
function Get-S3Directories {
param (
[string] $BucketName,
[bool] $Recurse …Run Code Online (Sandbox Code Playgroud) 我正在尝试date在PowerShell中将a DayOfWeek Month Day(st|nd|rd|th) year格式化为格式。
(Get-Date).AddDays(+1).ToString('D')
Run Code Online (Sandbox Code Playgroud)
输出为“ 2016年7月5日,星期二 ”,但需要使用以下格式:2016年7月5日,星期二
if date(Get-Date) % 100 IN (11, 12, 13) THEN 'th'
if (Get-Date) % 10 = 1 THEN 'st'
if (Get-Date) % 10 = 2 THEN 'nd'
if (Get-Date) % 10 = 3 THEN 'rd'
Run Code Online (Sandbox Code Playgroud)