2013-02-21 156 views
0

我想写一个批处理文件,以使网络用户/域的输出更加可用,因为需要在我工作的地方使用它的人不熟悉CLI接口。Windows批处理 - 输出命令输出的小提取

目前这是相当简单:

@echo off 

set /p id="Enter the ID of user: " %=% 

net user %id% /domain 

pause 

我在想,如果有只显示输出的特定部分的方法吗?

我只希望它输出活动帐户,到期和密码最后设置,到期。

我没有花太多时间编写脚本,所以我的知识很少,只限于python,但已被告知工作时我无法安装python来创建脚本,以便习惯使用widows批处理。

任何帮助都会很棒,或者如果有人知道windows批处理方面的良好知识基础,因为我发现的大多数站点都只是手册页的摘录。

回答

1

一个选项是转储到一个临时文件中的结果,然后使用find命令来呼应你想要什么:

@echo off 

set /p id="Enter the ID of user: " %=% 

net user %id% /domain > usertmp.txt 
type usertmp.txt | find "Account active" 
type usertmp.txt | find "Account expires" 
type usertmp.txt | find "Password last set" 
type usertmp.txt | find "Password expires" 

del usertmp.txt 

pause