파일 기반 LastWriteTime 속성 my 스크립트는 사용자 지정 출력이있는 'File Age'테이블을 만듭니다. 스크립트가 잘 작동, 내 문제는 특정 칼럼 '나이'의 출력으로 나는 그 것처럼 내가 명령을 설정합니다. 이미 "Sort-Object -descending"cmdlet을 사용하려고했지만 성공하지 않으면 데이터가 임의로 배치됩니다. 그걸 사용자 정의 할 수있는 또 다른 방법이 있을까요? 그런특정 열의 데이터 순서 변경
내 원하는 출력 모양 : 어떤 도움을 환영 할 것이다
$scan = gci c:\MyFolder
$scan | Add-Member ScriptProperty -Name FileAgeDays -Value {
[int]((Get-Date) - ($this.LastWriteTime)).TotalDays}
$scan | Add-Member ScriptProperty -Name FileAge -Value {
if ($this.FileAgeDays -le 7) {
"1 Day - 1 Week"
}
elseif ($this.FileAgeDays -ge 7 -and $this.FileAgeDays -le 30) {
"1 Week - 1 Month"
}
elseif ($this.FileAgeDays -ge 30 -and $this.FileAgeDays -le 180) {
"1 Month - 6 Months"
}
elseif ($this.FileAgeDays -ge 180 -and $this.FileAgeDays -le 365) {
"6 Months - 1 Year"
}
elseif ($this.FileAgeDays -ge 365 -and $this.FileAgeDays -le 730) {
"1 Year - 2 Years"
}
elseif ($this.FileAgeDays -ge 730) {
"< 2 Years"
}
}
$grp = $scan | ?{ ! $_.PSIsContainer } | Group FileAge |
Add-Member -MemberType ScriptProperty -Name SizeMB -Value {
($this.Group | Measure-Object Length -sum).Sum/1MB} -PassThru
$age_frag = $grp | select`
@{l='Size (MB)';e={"{0:n}" -f ($_.sizemb)}},`
@{l='Age';e={$_.name}}, Count|
ConvertTo-Html -Fragment -As Table -PreContent "<br><H2><a name=a009>File Age</a></H2>"|
Out-String
:
Age
1 Day - 1 Week
1 Week - 1 Month
1 Month - 6 Months
6 Months - 1 Year
1 Year - 2 Years
< 2 Years
가 여기 내 스크립트입니다.
안녕하세요. Frode 재생 해 주셔서 감사합니다. 주 스크립트에서 어떻게 구현할 수 있는지 잘 모르겠습니까? if 루프에서 어떻게 설정할 수 있습니까? – kekimian
테스트되지 않은 샘플의 업데이트 된 답변보기. –
큰 도움을 주셔서 감사합니다. – kekimian