다른 스레드의 도움으로 특정 폴더의 파일 이름을 가져오고 원본 파일의 더 큰 데이터베이스를 검색하고 '소유자'를 식별하는 스크립트를 작성했습니다. 현재 스크립트입니다 :여러 파일에서 소유자 메타 데이터를 가져 오는 PowerShell - 실패
$desktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)
$images = $desktopPath + '\Get_Owner'
Get-ChildItem -Path $images | Select BaseName | Export-Csv $desktopPath`\Filenames.csv -NoTypeInformation
$serverPath = 'C:\Users\tuggleg\Desktop\Archive'
$files = Import-Csv -Path $desktopPath`\Filenames.csv
#import filenames and search server for filename and owner
ForEach ($fileName in $files.BaseName)
{
Get-ChildItem -Path $serverPath -Filter "*$fileName*" -Recurse -ErrorAction 'SilentlyContinue' |
Select-Object -Property @{
Name='Owner'
Expression={(Get-Acl -Path $_.FullName).Owner}
},'*' |
Export-Csv -Path $desktopPath`\Owners.csv -NoTypeInformation
}
이 스크립트는 사용자가 로컬 파일 ($ 이미지)를 이동하고 파일 이름을 끌어 폴더를 목표로하고있다. 그런 다음 원본 파일에 대한 더 큰 데이터베이스 ($ serverPath)를 검색하고 소유자를 가져옵니다. 이 스크립트는 하나의 파일 이름으로 작동하지만 여러 파일이 '$ images'폴더에있을 때 '반복'하지 않고 계속 작동합니다. 나는 시도는 다음과 스크립트는 무기한 실행되지만 출력 CSV 데이터를 제공 나던 : 루프 기능은 스크립트를 나누기 이유
$desktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)
$images = $desktopPath + '\Get_Owner'
Get-ChildItem -Path $images | Select BaseName | Export-Csv $desktopPath`\Filenames.csv -NoTypeInformation
$serverPath = 'C:\Users\tuggleg\Desktop\Archive'
$files = Import-Csv -Path $desktopPath`\Filenames.csv
#import filenames and search server for filename and owner
#loop script
While($true) {
ForEach ($fileName in $files.BaseName)
{
Get-ChildItem -Path $serverPath -Filter "*$fileName*" -Recurse -ErrorAction 'SilentlyContinue' |
Select-Object -Property @{
Name='Owner'
Expression={(Get-Acl -Path $_.FullName).Owner}
},'*' |
Export-Csv -Path $desktopPath`\Owners.csv -NoTypeInformation
}
}
사람이 식별 할 수 있습니까? 또는 더 나은 이유는 초기 'foreach'문이 각 파일의 소유자를 초기에 제공하지 않는 이유입니다.
감사합니다.
나는 -NoClobber 들어 본 적이 없다! 나는 -Append와 no loop를 가지고 갔다. 너무 감사합니다 @가 레스 리용! – Garrett
여러분을 환영합니다! –
파일이 이미 존재하면'-NoClobber'는 오류가 발생합니다. 기본적으로 "파일을 덮어 쓰면 실패합니다". 내가 아는 한,'-NoOverwrite'와 동의어입니다. 실제로 파일에 추가하려면'-Append'를 지정해야합니다. –