Timeout issue with GetChildItem

I wrote a script to remote 500+ 2k3/2k8 servers for specific files with get-Childitem. It first check if the file exits and if the patch exits. The status is logged in one file and the result is logged in another file.

For some reason I am not getting any result back.

1.If I run one individually, it works and I see the search results.
gci -Pa \\serverA\d$ -In access.log error.log -Re

Open in new window


2. I got many "specified network name" errors, but obviously machines are online if I do a dir
\\serverA\d$.

Get-ChildItem : The specified network name is no longer available.
At getFile.ps1:30 char:6
+         gci <<<<  -Pa $fullsearchpath -In $fileList -Re| % {
    + CategoryInfo          : ReadError: (\\serverA\d$\ora...man\recv\errors:String) [Get-ChildItem], IOException
    + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

Open in new window


Complete code:
#################################################
$targetfile = "queryfilelist.txt";
$serverListfile = "testservers.txt";
$searchPath = "d$";
#################################################
if ( ! (test-path $targetfile) ) {
	write-host $targetfile not exist.
	break;
	} elseif ( ! (test-path $serverListfile) ) {
	write-host $serverListfile not exist.
	break;
	} else {
$fileList = gc $targetfile;
$serverList = gc $serverListfile;
$servcount = $serverList.count;
$logsuffix = Get-Date -Format "yyyyMM" ;
$log = "getFile-$logsuffix.log";
$out = "getFile-$logsuffix.out";
$progress = 1;
	foreach ($server in $serverList) {
	$date = Get-Date -Format "yyyyMMdd-hh:mm";
	$fullsearchpath = "\\$server\$searchpath";
	$logprefix="$date [$progress/$servcount][$($server.ToUpper())]";
	write-output "$logprefix - Searching file system." | Out-File -Encoding ASCII -a $log;
	if ( ! (test-connection $server -count 1 -q) ) {
		write-output "$logprefix - Host $server not reachable." | Out-File -Encoding ASCII -a $log;
		} elseif ( ! (test-path $fullsearchpath) ) {
		write-output "$logprefix - $fullsearchpath not exist." | Out-File -Encoding ASCII -a $log;
		} else {
		gci -Pa $fullsearchpath -In $fileList -Re| % {
		write-output "$logprefix - $($_.LastWriteTime) $($_.Length) $($_.FullName)"
		} | Out-File -Encoding ASCII -a -FilePath $out;
		}
	$progress++;
}

Open in new window

LVL 21
MazdajaiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The error message results from an interruption of the gci (as you can see in the error message, the path is some levels deep). Probably a network bandwidth issue, resulting in a timeout.
It is much better to let the dir command run remotely, and to only transfer the result to the controlling machine. That can be done by using WMI, PS Remoting or external tools like psexec from www.sysinternals.com.

Anyway, you should see at leat the attempts to access the servers in your log file, as that is written immediately. Strange you don't ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MazdajaiAuthor Commented:
Yup. I agreed the methodology but not all servers (Some are w2k3s) have powershell therefore I didn't go that route.

I commented out the following logics (test-connection and test-path) and it seems to resolved the issue.

Is there a way I can send the stderr of them to a log file?

if ( ! (test-connection $server -count 1 -q) ) {
		write-output "$logprefix - Host $server not reachable." | Out-File -Encoding ASCII -a $log;
		} elseif ( ! (test-path $fullsearchpath) ) {
		write-output "$logprefix - $fullsearchpath not exist." | Out-File -Encoding ASCII -a $log;

Open in new window

0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
test-connection -quiet doesn't send anything to stderr - it just results in a boolean. The same applies to test-path.
0
MazdajaiAuthor Commented:
Thanks.

It turns to be access issue. The user was using the wrong account to run the code. :(
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.