Se parecer que você precisa planejar o número de espaços entre o (s) nome (s) do trabalho
você usará essa lógica para e, em seguida, ajustará o tokens
e o variables
de acordo.
Para o " teste de trabalho de amostra ", use:
for /f "tokens=1-9" %%j in ('schtasks /Query /S [servername] /TN "Test Sample Job" /NH ^| findstr "Ready ^| Running"') do schtasks /Change /Disable /TN "%%j %%k %%l"
Note: This would not work for job names without spaces so you'll need a script per the job names with and without spaces. You'll need to have a separate script for job names with 2 spaces, 3 spaces, 4 spaces, and so on so you may need to standardize the job naming better or plan scripts accordingly.
Mais recursos
-
FOR /?
tokens=x,y,m-n - specifies which tokens from each line are to be passed to the for body for each iteration. This will cause additional variable names to be allocated. The m-n form is a range, specifying the mth through the nth tokens. If the last character in the tokens= string is an asterisk, then an additional variable is allocated and receives the remaining text on the line after the last token parsed. Some examples might help: FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k would parse each line in myfile.txt, ignoring lines that begin with a semicolon, passing the 2nd and 3rd token from each line to the for body, with tokens delimited by commas and/or spaces. Notice the for body statements reference %i to get the 2nd token, %j to get the 3rd token, and %k to get all remaining tokens after the 3rd. For file names that contain spaces, you need to quote the filenames with double quotes. In order to use double quotes in this manner, you also need to use the usebackq option, otherwise the double quotes will be interpreted as defining a literal string to parse. %i is explicitly declared in the for statement and the %j and %k are implicitly declared via the tokens= option. You can specify up to 26 tokens via the tokens= line, provided it does not cause an attempt to declare a variable higher than the letter 'z' or 'Z'. Remember, FOR variables are single-letter, case sensitive, global, and you can't have more than 52 total active at any one time.