问题描述
我正在使用以下批处理命令来检索所有本地用户配置文件(也包括域用户):
I was using the following batch command to retrieve all local user profiles (including domain users too) :
for /f "delims=" %%I in ('dir /a:d-h /b "%SystemDrive%\Users\*" 2^>nul ^| %SystemRoot%\System32\findstr.exe /i /l /x /v /g:"%bin%\exclude_users.txt"') do (
问题在于此命令有其局限性:它不会真正检查所涉及的用户是否确实拥有一个帐户.
The problem is that this command has its limits: it doesn't really check if the users in question do actually have an account.
Compo用户为我提供了一种使用WMIC检索配置文件名称的方法.
The user Compo provided me a methodology for retrieving the profile names, using WMIC.
所以我最终编写了以下命令:
So I ended up writing the following command:
@For /F "tokens=* skip=1" %%I In ('%__AppDir__%wbem\WMIC.exe UserAccount Get Name ^|%__AppDir__%findstr.exe /i /l /x /v /g:"%bin%\exclude_users.txt"') do (
问题是:它忽略了我的排除文件(每行包含一个用户),并且最终生成了一个没有任何名称的配置文件.
The problem is: it ignores my exclusion file (which contains one user per line) and it ends up a profile without any name.
有什么主意我该如何解决这些问题?
Any idea How I can solve these issues ?
推荐答案
@echo off
setlocal
set "bin=%~dp0"
for /f "tokens=* skip=1" %%I in ('
%__AppDir__%wbem\WMIC.exe UserAccount where Disabled^="FALSE" get Name ^|
%__AppDir__%WindowsPowerShell\v1.0\powershell -noprofile -command "$input.trim()" ^|
%__AppDir__%findstr.exe /i /l /x /v /g:"%bin%\exclude_users.txt"
') do echo "%%~I"
wmic
输出通过管道传输到powershell
进行修剪,然后通过管道传输到findstr
.
The wmic
output is piped to powershell
to be trimmed and then piped to findstr
.
wmic
命令将通过使用where
子句排除禁用的帐户.
The wmic
command will exclude disabled accounts by use of the where
clause.
根据需要更改bin
的设置.
这篇关于使用WMIC获取用户配置文件列表时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!