0

I have written script with the purpose of filtering different jobs which I ripped from a server based on the '@command=N'

$orginal_submap = 'C:\Users\Desktop\Jobs_from_Server\Jobs_Orgineel_opdr_2.3'

$orginal_rejected = 'C:\Users\Desktop\Jobs_from_Server\Jobs_Orgineel_opdr_2.3\gefaald'

$fileserver = Get-ChildItem $orginal_submap *.sql 

$stringfile = '@command=N''/FILE*'

$stringisserver = '@command=N''/ISSERVER*'

$commandline = '@command=N'

$startloop = 1 

foreach ($fileser in $fileserver)

{

$currentline = Select-String $fileser -pattern $commandline  

#countss how often the @command is containded in the file
$numberoftimesloopd = $currentline.length

do 

    { 
    if ($startloop -gt $numberoftimesloopd) {break}  
    foreach ($commandline in $currentline)

        { 
        $startloop

        if ($commandline -match $stringfile) {'@command=N''/FILE'}

        elseif ($commandline -match $stringisserver) {'@command=N''/ISSERVER'}

        else  {'gefaald'}

        #if the amount of loops is equel to the number of '@command=N' it stops the loop
        $startloop++ 
        if ($startloop -gt $numberoftimesloopd) {break}
    }

} while ($startloop-le  $numberoftimesloopd)

einde

}

My problem is that instead of quitting after running a job or simply gets the next *sql file from the source map it gives an error namely

enter image description here

It says that the error is in $currentline = Select-String $fileser -pattern $commandline

Problem is I have looked multiple times and try different things like adding start loop to stop the program to try keep running the script.

Can someone help solve the error and ensure that the script will quit if all files are done and if not take the next job from the source.

Or help me pinpoint the source of the problem/possible solution

0

1 Answer 1

1

In the following line you should use -SimpleMatch parameter so Select-String does not interpret the value of the Pattern parameter as a regular expression statement:

$currentline = Select-String $fileser -pattern $commandline -SimpleMatch
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the tip the code still doesnot loop troug all files and only reads the first. But the error is gone and that is certanily a imporvement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.