如何批量查询章输出重定向与FINDSTR? [英] How to redirect batch reg query output with findstr?

查看:800
本文介绍了如何批量查询章输出重定向与FINDSTR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本脚本只是从原来的完整文件约200-300注册表语句的一部分。按每个REG ADD statement.However,显然将这种脚本可以碰坏或一切它会将所有的注册表设置。
该脚本将在Windows 2008 R2服务器上应用。
声明原文
REG ADDHKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\控制\\ LSA/ V RestrictAnonymous的/吨REG_DWORD /天的1 / f

This script is only a portion of about 200-300 registry statements from the original full file. It sets all registry settings as per each reg add statement.However, applying this script obviously could break something or everything. The script will be applied on a Windows 2008 R2 server. Original statement reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /v RestrictAnonymous /t REG_DWORD /d 1 /f

我想申请这个脚本之前做到的是:
1.查询每个键检查重点用正确的数据存在
2.如果存在密钥和正确的数据,没有必要采取行动
3.如果密钥或数据的存在,将输出重定向到文件
  一个。我想为与不匹配的注册表项一起显示的结果
对于不匹配的注册表项被重定向输出将是那些我将手动检查。

What I want to accomplish before applying this script is: 1. Query each key to check if key exists with the correct data 2. If key and correct data exists, no action needed 3. If key nor data exists, redirect output to file a. I would like for the result to be displayed along with the registry key that does not match The redirected output for the non-matching registry keys will be the ones I will manually review.

下面再presents我attemps得出我请求的数据。我已经申请很多不同的开关(/ F / D |(管道)与FINDSTR)和重定向以不同的方式与所有没有运气。我还审查了reg compare命令,但因为我没有使用其他客户端来比较注册表是不适用的。出于某种原因,我不能让交换机的任意组合和命令根据需要工作。如果我得到所需的输出时,FINDSTR未正确验证。或者,如果FINDSTR正确验证,输出不显示。该FINDSTR结果似乎是合乎逻辑的语句,但结果不正确验证恩。 >> C:\\用户\\ AIODUDE \\文档\\ results.csv章查询HKLM \\ Software_reg_test/ V STIG_test | FINDSTR / E0
如果%ERRORLEVEL%EQU 0回声我匹配>> C:\\用户\\ AIODUDE \\文档\\ results.csv
如果%ERRORLEVEL%NEQ 0回声无匹配>> C:\\用户\\ AIODUDE \\文档\\ results2.csv

The following represents my attemps to derive the data I am requesting. I have applied many different switches (/f /d | (pipe) with findstr) and redirections in many different ways all with no luck. I also reviewed the reg compare command but it is not applicable because I am not using another client to compare the registry against. For some reason, I cannot get any combinations of switches and commands to work as desired. If I get the desired output, the findstr is not validating correctly. Or, if the findstr validates correctly, the output does not show. The findstr results seems to be the logical statement but the results are not validating correctly ex. >> C:\Users\AIODUDE\Documents\results.csv reg query "HKLM\Software_reg_test" /v STIG_test | findstr /E "0" if %ERRORLEVEL% EQU 0 echo I match >> C:\Users\AIODUDE\Documents\results.csv if %ERRORLEVEL% NEQ 0 echo No match >> C:\Users\AIODUDE\Documents\results2.csv

记住,这个脚本有200-300注册表中添加语句。

Remember, this script has about 200-300 registry add statements.

::all reg add keys are only set to do not read during testing
::reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /v RestrictAnonymous /t REG_DWORD /d 1 /f

reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /v RestrictAnonymous > D:\results.csv
if %ERRORLEVEL% EQU 0 echo I match >> D:\results.csv
if %ERRORLEVEL% NEQ 0 echo No match >> D:\results.csv


::reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\EventLog\Setup" /v MaxSize /t REG_DWORD /d 32768 /f

reg query "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\EventLog\Setup" /v MaxSize >> D:\results.csv
if %ERRORLEVEL% EQU 0 echo I match >> D:\results.csv
if %ERRORLEVEL% NEQ 0 echo No match >> D:\results.csv


::reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /t REG_DWORD /d 0 /f

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated >> D:\results.csv
if %ERRORLEVEL% EQU 0 echo I match >> D:\results.csv
if %ERRORLEVEL% NEQ 0 echo No match >> D:\results.csv

pause

Endoro - 我回答,因为这里的评论限制。
您的发言给了我最需要我迄今为止的数据 - 感谢您的!我曾尝试各种几十构造!该FINDSTR比赛,我需要的确切数据。下述实施例与输出重定向如果密钥未发现的异常工作。我决定用一组语句进行编辑数百行轻松了不少:

Endoro--I answered here because of the comments limitation. Your statement gives me most of the data I need thus far--thanks for that!. I have tried dozens of various constructs! The findstr matches the exact data that I need. The below examples work with the exception of redirecting the output if the key is not found. I decided to use set statements to make editing the hundreds of lines a lot easier:

set _results=C:\Users\AIODUDE\Documents\xresultsd.txt

set _NEQ=%_results% 2>&1 && echo success || echo FAIL >> %_results%

set _EQU=%_results% 2>&1 && echo success || echo FAIL >> %_results%

这个例子是好的如果匹配,则输出状态。(我匹配 - 所以这关键是良好的,并没有进一步的动作)

THIS EXAMPLE IS GOOD If it matches, the output states (I match--so this key is good and no further action).

reg query "HKLM\Software\_reg_test" /f STIG_test /e >>%_results%
reg query "HKLM\Software\_reg_test" /v STIG_test | findstr "0"
if %ERRORLEVEL% NEQ 0 echo No match >>%_NEQ%
if %ERRORLEVEL% EQU 0 echo I match >>%_EQU%

这个例子中有一个非匹配的数据VLAUE 需要采取行动。

THIS EXAMPLE HAS A NON-MATCHING DATA VLAUE Action is needed.

REG Query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /f RestrictAnonymous /e >>%_results%
reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /v RestrictAnonymous | findstr "1"
if %ERRORLEVEL% NEQ 0 echo No match >>%_NEQ%
if %ERRORLEVEL% EQU 0 echo I match >>%_EQU%

在这个例子中,第一章第查询语句仅搜索特定键和打印出的密钥和数据值。但是,它没有标识的正确值应该是什么,因此...
第二章第查询语句做标识的正确的值,但不打印出该值应该是什么(此声明将需要动作 - 在这种情况下,这种情况下的数据值应该是0

In this example, the first reg query statement searches only the specific key and prints out the key and data value. However, it does not ID what the correct value should be hence... The second reg query statement does ID the correct value but does not print out what that value should be (this statement will need action--in this case this case data value should be 0.

这个例子中的注册表项未找到需要采取行动。

THIS EXAMPLE REGISTRY KEY IS NOT FOUND Action is needed.

reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /f LmCompatibilityLevel /e >>%_results%
reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /v LmCompatibilityLevel | findstr "5"
if %ERRORLEVEL% NEQ 0 echo No match >>%_NEQ%
if %ERRORLEVEL% EQU 0 echo I match >>%_EQU%

所以FINDSTR(显示我,我需要添加或修改特定的数据),如果它可以从所有报表打印是很理想的,限制我的搜索和编辑,只不匹配值的数据,如果关键是不是已经present。

So the findstr (shows me the specific data I need to add or modify), if it could print from all statements would be the ideal and limit my search and editing to only the value data that does not match and if the key is not already present.

推荐答案

尝试有点像这样的:

reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa" /v RestrictAnonymous >results.csv 2>&1 && echo success || echo FAIL >> results.csv
type results.csv

这篇关于如何批量查询章输出重定向与FINDSTR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆