Reputation: 91
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
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
Upvotes: 0
Views: 68
Reputation: 178
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
Upvotes: 1