function foo()
{
# get a list of files matched pattern and timestamp
$fs = Get-Item -Path "C:\Temp\*.txt"
| Where-Object {$_.lastwritetime -gt "11/01/2009"}
if ($fs -ne $null) # $fs may be empty, check it first
{
foreach ($o in $fs)
{
# new bak file
$fBack = "C:\Temp\test\" + $o.Name + ".bak"
# Exception here Get-Item! See following msg
# Exception thrown only Get-Item cannot find any files this time.
# If there is any matched file there, it is OK
$fs1 = Get-Item -Path $fBack
....
}
}
}
예외 메시지는 ... 기본적으로 The WriteObject and WriteError methods cannot be called after the pipeline has been closed. Please contact Microsoft Support Services.
, 나는 함수 내에서 다시 Get-Item
를 사용하거나 할 수없는 폐쇄 된 파이프 라인 오류와 함께 실패 루프를 사용하여 다른 폴더의 파일 목록을 가져옵니다.
설명과 문제를 해결하는 올바른 방법은 무엇입니까?
그런데 PS 1.0을 사용하고 있습니다.
David, 코드 샘플의 마지막 줄에서 Get-Item을 호출하면 백업 파일이 'C : \ temp \ test \'디렉토리에 만들어 졌는지 확인하기 만하면됩니까? – MagicAndi
$ fs = @ (Get-Item c : \ temp \ *. txt |? {$ _. lastwritetime -)}와 같은 배열 부분 표현식 연산자를 사용하여 if ($ fs -ne $ null) gt; "11/01/2009"}}); foreach ($ file in $ fs) {...} –
해결 방법이 있습니다. 하지만 아무도 여기서 무슨 일이 일어나는 지 알아? – stej