Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Powershell Test-Path hanging Expand / Collapse
Author
Message
Posted Friday, May 16, 2014 9:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 11, 2014 9:14 AM
Points: 5, Visits: 57
I am running a script that checks for mdf and ldf files on all of our SQL Servers and the script gets about halfway through before it hangs. It hangs at the line:
Test-Path $fullPath

Where $fullPath is the complete file path. Like I said, the script works perfectly fine and it tests half of the file paths in the list but after about half way, it will hang here.

Could this be something to do with the file it gets hung on or the path? I have taken this snippet out of the script and executed it with the path that the script keeps getting hung on and it returned true within milliseconds.

Please note that it hangs on the same file/same spot every time.
Post #1571779
Posted Friday, May 16, 2014 9:28 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:37 AM
Points: 5,425, Visits: 3,161
Without the context (a bit more of the script) I don't think I would have a clue. Sorry.

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Post #1571790
Posted Friday, May 16, 2014 9:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 11, 2014 9:14 AM
Points: 5, Visits: 57
I have added more of the code around the call from my script.
 
$serverName = "NTDBTH3000M00"
$root = "D"
$path = "\Scripts\PowerShell\test.mdf"

$fullPath = $("\\"+$serverName+"\"+$root+"-root"+$path)
if(Test-Path $fullPath){
$fileSize = (Get-Item $fullPath).length
Write-Host $fileSize
}
else {
Write-Host "The path does not exist"
}
Post #1571802
Posted Friday, May 16, 2014 10:09 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:37 AM
Points: 5,425, Visits: 3,161
Looks good from here. Sorry I couldn't help.

I take it that you have written out to the console to ensure that it is freezing when you believe it is.


Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Post #1571809
Posted Friday, May 16, 2014 10:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 11, 2014 9:14 AM
Points: 5, Visits: 57
Yea. It is set up in a loop where it cycles through the different $path variables. It makes it through half of the paths and all of the results print out correctly but when it reaches a certain path, it gets hung. I know it is at the test path because I have done some debugging and wrote to the console before and after the Test-Path statement and it reaches the before but not the after for the path it hangs on.
Post #1571816
Posted Friday, June 6, 2014 4:54 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, September 15, 2014 2:29 PM
Points: 17, Visits: 52
How long is the path it's getting stuck on? Does it contain any "weird" characters like square brackets, etc?
Post #1578235
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse