通过命令提示符在整个域中搜索文件
有没有办法通过命令提示符在整个域中搜索特定文件。
我正在使用 dir/s Example.txt
但当然这只搜索一台特定的计算机。
Would there be a way to search an entire domain for a specific file through the command prompt.
I am using dir/s Example.txt
but of course that only searches one specific computer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 VBScript 中的 LDAP 查询从域中获取计算机对象列表,然后使用 For Each 迭代计算机列表,然后依次在每台计算机上执行 dir /s 命令并读取输出命令并解析您的结果以查看是否成功。
它不会很漂亮,但它会起作用。
编辑
它会使用当时运行可执行文件的任何凭据。使用 WinNT 是可以的,但如果您想正确执行此操作,请使用 DirectoryServices (我知道它是 C#,但你可以从那里得到漂移并可以使用 this< /a> 转换)命名空间。
获得计算机列表后,您需要遍历它们并对每台计算机运行命令/进程。
You could get a list of computer objects from the domain using an LDAP query in a VBScript, then iterate through the list of computers using a For Each and then execute the dir /s command on each of the computers in turn and read the output from the command and parse your results to see if you get a hit.
It wouldn't be pretty but it'd work.
EDIT
It'd use the credentials of whatever was running the executable at the time. Using WinNT is ok, but if you want to do it properly, use the DirectoryServices (I know it's C#, but you get the drift from there and can use this to convert) namespace.
Once you have your list of computers, you need to iterate through them and run your command/process against each computer.
一种简单的方法是获取计算机列表,然后使用 UNC 路径和管理共享 ([驱动器号]$) 访问它们。您必须使用在所有计算机上具有管理访问权限的帐户来执行此操作。
\\computer01\c$\windows
这将为您提供computer01 上的windows 文件夹。将其放入 for-each 循环中,然后照常进行搜索。
另外,根据您正在查看的计算机数量和网络条件,如果您生成一些工作线程,您可能能够加快速度。
One easy way would be to get a computer list, and then access them using the UNC path and the administrative shares ([driveletter]$). You would have to do this from an account with administrative access on all of the computers.
\\computer01\c$\windows
That would give you the windows folder on computer01. Throw that in a for-each loop, and do the searching as normal.
Also depending on the number of computers you are looking at, and the network conditions, you might be able to speed things up if you spawned a few worker threads.