2014-09-23 3 views
2

나는 Videos라는 디렉터리가 있습니다. 이 디렉토리 안에는 다양한 카메라의 하위 디렉토리가 있습니다. 다양한 카메라를 확인하고 특정 날짜보다 오래된 기록을 삭제하는 스크립트가 있습니다.Powershell의 전체 경로 정보 얻기

카메라의 전체 디렉토리 정보를 가져 오는 데 문제가 있습니다.

#Get all of the paths for each camera 
$paths = Get-ChildItem -Path "C:\Videos\" | Select-Object FullName 

을 그리고 $ 경로의 각 경로를 통해 나는 루프 내가해야 할 어떤 삭제 : I 스크립트를 실행하면

foreach ($pa in $paths) { 
    # Delete files older than the $limit. 
    $file = Get-ChildItem -Path $pa -Recurse -Force | Where-Object { $_.PSIsContainer -and $_.CreationTime -lt $limit } 
    $file | Remove-Item -Recurse -Force 
    $file | Select -Expand FullName | Out-File $logFile -append 
} 

, 나는 점점 오류가 나는 나는 그것을 얻기 위해 다음과 같은 사용하고 예 :

@{FullName=C:\Videos\PC1-CAM1} 
Get-ChildItem : Cannot find drive. A drive with the name '@{FullName=C' does not exist. 
At C:\scripts\BodyCamDelete.ps1:34 char:13 
+  $file = Get-ChildItem -Path $pa -Recurse -Force | Where-Object { $_.PSIsCont ... 
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+ CategoryInfo   : ObjectNotFound: (@{FullName=C:String) [Get-ChildItem], DriveNotFoundException 
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand 

@ {FullName = 경로에서 제외 하시겠습니까? 그게 문제가 될 수 있다고 생각합니다.

답변

4

$pa은 FullName 속성이있는 개체입니다. 당신이 접근하는 방법은 이것 일 것입니다. 그냥 간단하게 될 것입니다 그러나

$file = Get-ChildItem -Path $pa.FullName -Recurse -Force | Where-Object { $_.PSIsContainer -and $_.CreationTime -lt $limit } 

는이 라인을 변경하고
$paths = Get-ChildItem -Path "C:\Videos\" | Select-Object -ExpandProperty FullName 

-ExpandProperty

그냥 대신 Select-Object가 반환되었다는 객체의 문자열을 반환합니다 나갑니다.

1

거의 다 왔어. 원하는 것은 Select-Object에 대한 -ExpandProperty 인수입니다. 이 속성은 하나의 속성을 가진 FileInfo 개체 대신 해당 속성의 값을 반환하며 그 속성은 FullName입니다. 이것은 당신을 위해 그것을 해결해야

$paths = Get-ChildItem -Path "C:\Videos\" | Select-Object -ExpandProperty FullName 

편집 : 매트 분하여 저를 이길처럼 보인다.

관련 문제