0

我需要创建一个批处理脚本。

这个脚本应该能够检测到是否有结果。

我正在使用命令

dsquery domainroot -inactive 60

它告诉我所有已停用 60 天的帐户。

我运行相同的命令 180 天,但没有得到任何结果。

我运行该命令 60 天,我得到了结果。

我需要创建退出代码来确定是否有任何结果。

这些中的每一个的错误级别都是 0(有和没有结果)。

有没有其他方法可以检测是否有结果。所以我可以把它变成一个 IF 语句。

4

3 回答 3

0

这将查找至少两行结果,更改1 21仅查找
dsquery domainroot -inactive 60|file.bat
if %errorlevel%==1 echo no results
if %errorlevel%==0 echo results

一行 file.bat
for %%i in (1 2) do set /p a=
if defined a exit 0 /b
exit 1 /b

于 2013-10-04T15:10:32.907 回答
0

应该按照你的要求做:

@echo off
dsquery domainroot -inactive 60 |find /v "" >nul
if errorlevel 1 (
     echo no result
  ) else (
     echo results found
  )
于 2013-10-05T12:46:43.677 回答
0

在用脚本解决了这个问题后,我需要将此脚本添加到 GFI。下面的脚本允许您检测 60 天不活动的用户并报告结果。

如果您将此脚本上传到 GFI MAX RMM,它将无法通过脚本检查并向您报告结果并将它们转发到您的 PSA 系统(如果您已配置)。

自动生成的票证,让您知道客户没有让您知道有人可能已经离开公司,什么不喜欢。

@echo off
REM This batch  script was created by som3guy.
REM Cleans up any previous runs of this batch command.
cd %temp%
Del Inactiveusers.txt
echo "The following user(s) have been inactive for 60 days or more:" > Inactiveusers.txt
REM Saves a file called Inactiveusers.txt to the %temp% dir for analysis.
dsquery user domainroot -inactive 60 >> Inactiveusers.txt
GOTO Check

REM Check the filesize and sets as a variable.
:CHECK
for %%A in (%temp%/Inactiveusers.txt) do set fileSize=%%~zA
REM Determines if there is data in the file or not. And sends to appropriate Function.
IF %filesize% == 59 (GOTO NonExistant) ELSE (GOTO Existant)


:Existant
REM The below command parses Inactiveusers.txt for data and sends it to GFI via ECHO
for /f "delims=" %%i in (%temp%/Inactiveusers.txt) do echo %%i
REM Exit code for GFI
exit 1000


:NonExistant
REM No inactive users.
REM Exit code for GFI
exit 0
于 2013-10-06T10:45:26.763 回答