2013-02-21 154 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