Powershell Test-Path hanging

  • 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.

  • 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!!!

  • 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"

    }

  • 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!!!

  • 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.

  • How long is the path it's getting stuck on? Does it contain any "weird" characters like square brackets, etc?

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply