SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Powershell Test-Path hanging


Powershell Test-Path hanging

Author
Message
anthonylabuda
anthonylabuda
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 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.
Gary Varga
Gary Varga
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16631 Visits: 6534
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!!!
anthonylabuda
anthonylabuda
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 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"
}

Gary Varga
Gary Varga
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16631 Visits: 6534
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!!!
anthonylabuda
anthonylabuda
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 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.
andycadley
andycadley
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 123
How long is the path it's getting stuck on? Does it contain any "weird" characters like square brackets, etc?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search