2012-12-09

Adfind

http://www.joeware.net/freetools/tools/adfind/index.htm


adfind –b <Search Base> -s <Search Scope> -f <Search Filter> attributesDesired

1.所以對域中所有計算機對象的DN 和說明的查詢應為:
adfind –b dc=contoso,dc=com –s subtree –f (objectcla​​ss=computer) dn description

2.對所有用戶對象的查詢如下所示:
adfind –b dc=contoso,dc=com –s subtree –f "(&(objectcategory=person) (objectcla​​ss=user))" dn description

Forfiles


http://technet.microsoft.com/en-us/library/cc753551(WS.10).aspx
Syntax

forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d[{+ | -}] [{MM/DD/YYYY | DD}]]

Parameters

/p Path
指定您要在其上開始搜尋的 Path。預設資料夾為目前的工作目錄,您可以透過輸入句點 (.) 來指定。
/m SearchMask
依據 SearchMask 來搜尋檔案。預設的 SearchMask 為 *.*。
/s
指示 forfiles 在子目錄中搜尋。
/c Command
在每個檔案上執行指定的 Command。您必須將帶有空格的命令字串包含在引號中。預設的 Command 為 "cmd /c echo @file"。
/d[{+ | -}] [{MM/DD/YYYY | DD}]
選取日期大於等於 (+) 或小於等於 (-) 指定日期的檔案,其中 MM/DD/YYYY 是指定的日期,而 DD 是目前日期減去 DD 天。如果您未指定 + 或 -,則會使用 +。DD 的有效範圍為 0 - 32768。
/?
在命令提示字元上顯示說明。
Remarks

Forfiles 最常使用於批次檔案中。

Forfiles /s 與 dir /s 類似。
下列表格列出了您可以在 /cCommand 命令字串中使用的變數。

變數 描述
@file 檔案名稱

@fname 不含副檔名的檔案名稱

@ext 副檔名

@path 檔案的完整路徑

@relpath 檔案的相對路徑

@isdir 如果檔案類型是目錄,則判斷值是 TRUE,否則判斷值是 FALSE。

@fsize 檔案大小 (以位元組為單位)

@fdate 檔案上的上次修改日期戳記

@ftime 檔案上的上次修改時間戳記

使用 forfiles,您可以在多個檔案上執行命令,或將引數傳送到多個檔案。例如,您可以在樹狀目錄中帶有 *.txt 副檔名的所有檔案上執行 TYPE 命令。或者,您可以執行 C: 磁碟機上的每個批次檔案 (*.bat),以檔案名稱 Myinput.txt 作為第一個引數。

使用 forfiles,您可以執行下列任何一項動作:

使用 /d 按絕對或相對日期選取檔案。

使用變數,例如 @fsize (檔案大小) 及 @fdate (檔案日期),來建立檔案的保存樹狀目錄。

使用 @isdir 變數以從目錄中區分檔案。

藉由在命令列中包含特殊字元,及使用十六進位字碼 0xHH 包圍字元,來格式化輸出。

Forfiles 藉由執行工具 (設計用於僅處理單一檔案)上的 recurse subdirectories 旗標來運作。

Examples

若要列出 C: 磁碟機上的所有批次檔案,請輸入:

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

若要列出 C: 磁碟機上的所有目錄,請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

若要列出 C: 磁碟機上 100 天之前的所有檔案,請輸入:

forfiles /p c:\ /s /m *.* /dt-100 /c "cmd /c echo @file :date >= 100 days"

若要列出 C: 磁碟機上 1993 年 1 月 1 日之前的所有檔案,再為這些檔案顯示 "file is quite old!",請輸入:

forfiles /p c:\ /s /m *.* /dt-01011993 /c "cmd /c echo @file is quite old!"

若要列出 C: 磁碟機上所有檔案的所有副檔名(按欄位格式),請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c echo extension of @file is 0x09@ext0x09" With:

若要列出 C: 磁碟機上的所有批次檔案,請輸入:

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

若要列出 C: 磁碟機上的所有目錄,請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

若要列出 C: 磁碟機上 100 天之前的所有檔案,請輸入:

forfiles /p c:\ /s /m *.* /d t-100 /c "cmd /c echo @file :date >= 100 days"

若要列出 C: 磁碟機上 1993 年 1 月 1 日之前的所有檔案,再為這些檔案顯示 "file is quite old!",請輸入:

forfiles /p c:\ /s /m *.* /d t-01011993 /c "cmd /c echo @file is quite old!"

若要列出 C: 磁碟機上所有檔案的所有副檔名(按欄位格式),請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c echo extension of @file is 0x09@ext0x09"


#刪除超過7天,位於 c:\windows\Temp 路徑中檔名 sess開頭的檔案
forfiles /P c:\Windows\Temp /M sess_* /S /D -7 /C "cmd /c del /F @path"