파일 공유 서버 정리

파일 공유 서버 정리

저는 모든 파일과 폴더, 생성 날짜와 마지막 액세스 날짜, 크기(MB), 가능한 경우 마지막으로 액세스한 사람을 나열하는 PowerShell 스크립트를 CSV 파일로 내보내려고 노력했습니다.

몇 가지 스크립트를 테스트하고 다른 게시물의 도움도 받았지만 모든 파일을 가져오지는 않습니다.

현재 실행 중인 스크립트는 다음과 같습니다.

 Get-ChildItem c:\Users\iceledon -Recurse -ErrorAction SilentlyContinue |  Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-365)} |
Export-Csv "C:\Users\iceledon\Desktop\files.csv" -NoTypeInformation

답변1

이것이 파일 속성에서 얻을 수 있는 전부입니다. 선택한 첫 번째 파일의

# This is all you can get from file properties. of the first file selected
(Get-ChildItem 'd:\temp\*.txt')[0] | Select-Object -Property *

# Results

PSPath            : Microsoft.PowerShell.Core\FileSystem::D:\temp\1 passwordchangelog.txt
PSParentPath      : Microsoft.PowerShell.Core\FileSystem::D:\temp
PSChildName       : 1 passwordchangelog.txt
PSDrive           : D
PSProvider        : Microsoft.PowerShell.Core\FileSystem
PSIsContainer     : False
Mode              : -a----
VersionInfo       : File:             D:\temp\1 passwordchangelog.txt
                    InternalName:     
                    OriginalFilename: 
                    FileVersion:      
                    FileDescription:  
                    Product:          
                    ProductVersion:   
                    Debug:            False
                    Patched:          False
                    PreRelease:       False
                    PrivateBuild:     False
                    SpecialBuild:     False
                    Language:         

BaseName          : 1 passwordchangelog
Target            : {}
LinkType          : 
Name              : 1 passwordchangelog.txt
Length            : 24
DirectoryName     : D:\temp
Directory         : D:\temp
IsReadOnly        : False
Exists            : True
FullName          : D:\temp\1 passwordchangelog.txt
Extension         : .txt
CreationTime      : 10-Jul-18 16:30:22
CreationTimeUtc   : 10-Jul-18 23:30:22
LastAccessTime    : 10-Jul-18 16:30:22
LastAccessTimeUtc : 10-Jul-18 23:30:22
LastWriteTime     : 06-Jul-18 22:16:24
LastWriteTimeUtc  : 07-Jul-18 05:16:24
Attributes        : Archive

위의 파일 개체 속성에서 볼 수 있듯이. 누가 마지막으로 액세스했는지에 대한 정보는 없습니다. 마지막으로 길이를 KB, MB 등으로 변환해야 합니다.

그래서 이렇게 하는군요...(출력을 위해 Format-Table을 사용하지 마세요. 이것은 단지 화면용입니다.)

Get-ChildItem 'd:\temp' -Recurse -ErrorAction SilentlyContinue `
| Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-365)} `
| Select FullName,CreationTime,LastAccessTime,
    @{Name='Size(kb)';Expression={“{0:F2}” -f ($_.length/1KB)}},
    @{Name='Size(mb)';Expression={“{0:F2}” -f ($_.length/1MB)}} `
| Sort-Object -Property LastAccessTime `
| Format-Table -AutoSize

FullName                                       CreationTime       LastAccessTime     Size(kb) Size(mb)
--------                                       ------------       --------------     -------- --------
D:\temp\4 passwordchangelog.txt                05-Jul-18 13:15:04 05-Jul-18 13:15:04 0.02     0.00    
D:\temp\1 passwordchangelog.txt                10-Jul-18 16:30:22 10-Jul-18 16:30:22 0.02     0.00    
D:\temp\10 passwordchangelog.txt               10-Jul-18 16:30:26 10-Jul-18 16:30:26 0.02     0.00 
...

무슨 말이에요?

하지만 모든 파일을 가져오지는 않습니다.

GCI는 귀하에게 권한이 있는 한 귀하가 요청하는 모든 파일을 처리합니다. 어쨌든 필터링하면 그것이 반환되는 전부입니다.

추가일수(-365)

이는 다음보다 오래된 파일만 나에게 제공한다는 의미입니다. 따라서 설계상 이전보다 오래되지 않은 것은 얻을 수 없습니다.

관련 정보