Is my java call script looping?

I wrote this script that runs well for 90% of what it does, which is the weird thing as it seems to have an issue completing another iteration of exactly where its successful.

Line 56 has a typo that reads $TIMS when it should read $TPS - not sure how to change it as I don’t have a github account.

It starts a vpn. Scans ALL drives for a specifically named folder, iterates that result into a java call.

Now the java jar functions perfectly for anything that’s caught in the C:\ drive but it seems to either hang or loop or run indefinitely for any folder not base in c:.

I can’t even kill it with sysinternals pkill or stop-process. When I try to reboot the system the whole thing hangs.

On my test machine it seems to hang on the F:\ drive. The report the java file creates makes an F__verifier.log report (two underscores because everything in C:\ is in projects, but I chalked that up to just the log generator and not the actual launching of the java jar.

https://gist.github.com/anonymous/d4fe7212b5c624bf3b77c35d7f9b48bf

Are the non-C: drives local?

The one in the case I am reviewing the drive is not local, it’s a usb external (which is often the case with these remote systems).

I have a feeling the problem I’m running into is hardware related, in-part.
Because of a couple bad reboots where the end user was required I looked into event manager and found loads of bad block messages originating from the external drive.

My main worry was that the script would stay forever on the external drive (there is only 1 project on it).
The script ran two scans simultaneously and completed many other projects until only the project on the external remained, and seemingly never went away.

The fear was that somehow the script was looping the external drive. It definitely completed and did not loop the local drive projects.

Thank you

Just had one of those “process won’t die” experiences with this script. It had been running for about 12 hours and I threw everything at it. pskill, kill, stop-process, all the fun stuff.

I threw so many things at it in the end I have no idea what actually took it out.

This was all after I already stopped the task in Task Manager.

This system has a real hang-up with this script. Strange that it only effects this one thread. All the rest end with expected results.
The java call in task manager looks perfect…

Cannot determine if it’s looping or just train-wrecking.

About to deploy this on over a hundred systems but may need to postpone.

Hmm… I just got a nasty surprise

on a hunch I removed lines 55 & 57 and changed 56 to say Write Host “$($Projects[$]) $($TIMS[$])”

Now on my personal system I have a lot of drives
The result was 10 lines from C:, 3 lines for D:\ and 1 from H:
All the $Project entries are correct for all 14 results, no more or less than what was expected.
The $TIMS entry for C:\ and H:\ are correct.
D:\ is messed up. All 3 $TIMS entries are wrong. However they only swap within results of D:\

The primary issue I see is that in the other drives $projects are found in the same folder structure.
Either in the root of the drive or found within a “Projects” folder. The exception is D:\ where $Projects are found in both the root and within 1 directory below root.

What can I do? :slight_smile:

So… keep in mind I’m operating blind ;). I don’t understand what “$TIMS entries are wrong” means, because I don’t know what either “right” or “wrong” is meant to look like. Can you help me understand what data you’re dealing with, and what outcome you’re looking for?

so the verifier needs to find the project which we can do without problem using $projects.
The folder name of $projects is what I’m trying to find in $TIMS but perhaps I’m over complicating things.

The end result I need is C:\Projects\12345 12345 I need those two 12345’s to match exactly.
I was trying to reference the array but it’s not working out.

Maybe a more reliable and simpler way is to extract everything after the last slash and join it to the end…

Yeah, I’m still distinctly unclear on what the data DOES look like and what the data SHOULD look like, so I’m going to be utterly useless to you. Keep in mind, I’m not in your environment and I can’t run your code.

Sorry to waste your time by being unclear

My data set could look like this:

C:\112233
C:\Projects\112233
C:\Projects\444555
C:\1234A
H:\Projects\66566
H:\987654
I:\321654

These results are easy to find. $projects does a good job of that. The number of results can vary (both drive letter, number of drives returned and directories, whose name’s are random).

When I pipe the results into the java file (seems to work) whatever that last folder name is I need to tag it to the end.

So C:\1234A must follow with 1234A and nothing else or else it won’t work. C:\1234A 1234A
H:\Projects\66566 must follow with 66566 so result will be H:\Projects\66566 66566

I hope I’ve been more clear.

Thank you so much for your time.

Ah. So you need to extract the last segment of the folder and then append a space, and the last segment, to the folder.

function pathstuff {
 param([string[]]$folder)
 foreach ($fold in $folder) {
  $segments = split-path $fold
  write-output "$fold $($segment[-1])"
 }
}

Like that? You can call pathstuff, and pass in either a single folder or a collection of folders (strings), and get out what you want.

I receive a NullArray error.

I’m doing

$Projects = Get-PSDrive -Name $redac |
     ForEach-Object{Set-Location $_.Root -EA 0; 
       Get-ChildItem -Recurse -Depth 1 | 
       Where-Object {$_.PSIsContainer} | 
       Where-Object {$_.Name -match "^[0-9]{5,6}[a-zA-Z]?$"} |
       Sort-Object -Unique |
       Foreach-Object{
            $_.FullName
            }
          } 
 pathstuff $projects

Which will give me C:\1234A
Cannot index into a null array.
At line:7 char:25

  • write-output “$fold $($segment[-1])”
  •                     ~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:slight_smile: [], RuntimeException
    • FullyQualifiedErrorId : NullArray

for each result.

I tried

pathstuff C:\1234A

with same result.

Ok that was just a letter missing: Line 5 needed an ‘s’ on $segment.

However the result is now

C:\1234A \ ( a space between A and \ )

Yeah, sorry, I’ve got two projects open right now and I copied you the wrong one.

function pathstuff {
 param([string[]]$folder)
 foreach ($fold in $folder) {
  $folder = $fold -replace "/","\"
  $segments = $fold -split "\\"
  write-output "$fold $($segments[-1])"
 }
}

That should actually do it.

I’m aaaaalllmost there.

function pathstuff {
 param([string[]]$folders)
 foreach ($fold in $folders) {
  $segments = split-path -Path $fold -Leaf
  write-output "$fold $($segments)"
 }
}

Now there are absolutely no mistakes - thank you Don!

however… it repeated the last entry twice. I wonder why it would do that?

This, oddly enough - had the exact same results
It repeated the last entry twice.

Can it be my $projects array?

Steve

Fixed:

 foreach ($fold in $folders |
 Sort-Object $_ -Unique
 )

So both approaches work with sort-object $_ -Unique

function pathstuff {
 param([string[]]$folders)
 foreach ($fold in $folders |
 Sort-Object $_ -Unique
 ) {
  $segments = split-path -Path $fold -Leaf
  write-output "$fold $($segments)"
 }
}

and

function pathstuff {
 param([string[]]$folder)
 foreach ($fold in $folder | 
 Sort-Object $_ -Unique
 ) {
  $folder = $fold -replace "/","\"
  $segments = $fold -split "\\"
  write-output "$fold $($segments[-1])"
 }
}

Thanks a bunch!