Link to home
Start Free TrialLog in
Avatar of Mazdajai
MazdajaiFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mazdajai

ASKER

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

test-connection -quiet doesn't send anything to stderr - it just results in a boolean. The same applies to test-path.
Thanks.

It turns to be access issue. The user was using the wrong account to run the code. :(