I am new to PS. Here is an example of my function codes:
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 exception message is "The WriteObject and WriteError methods cannot be called after the pipeline has been closed. Please contact Microsoft Support Services."
Basically, I cannot use Get-Item again within the function or loop to get a list of files in a different folder. Not sure why. Any explanation and what is the correct way to fix it?
By the way I am using PS 1.0.