列出工作站上的所有用户帐户

Listing all user accounts on a workstation

我正在编写一个脚本,用于使用 USMT 将用户配置文件从工作站备份到服务器,但我 运行 遇到了麻烦,无法找到在工作站上列出配置文件的方法。我们所有的个人资料都是基于域的,我能找到的每篇文章都只列出本地个人资料,而不是域帐户。

我很想知道是否有人有简单的方法来做到这一点,或者其他人是如何接近这个的?我曾想过只列出 C:\Users 中的文件夹,然后交叉引用 AD 来获取域帐户,但是该项目的一部分是能够从其他域中获取帐户并将它们加入另一个域,所以认为这行不通.

所以如果有人能给我一些关于这个的指点或文章,我将不胜感激。

听起来您想要本地系统上的帐户配置文件列表。我知道的最直接的方法是使用 Win32_UserProfile class.

代码的作用...

  • 抓取所有帐户资料
    您可以使用 -Filter 参数只获取您想要的参数,但我不明白 CIM/WMI.
  • 使用的查询语言方言
  • 过滤掉 .Special 个帐户
    systemprofile 之类的东西不太可能被需要。 [咧嘴一笑]
  • 将调用包装在 @() 中以强制结果为数组
    这里的重点是确保结果是一个数组——即使其中只有一个项目。将结果视为一个数组可能很有用,所以我强制它是一个数组。
  • 将结果分配给 $Var
  • 显示该列表

代码...

$UserProfileList = @(
    Get-CimInstance -ClassName Win32_UserProfile |
        Where-Object {-not $_.Special}
    )

$UserProfileList

仅一个配置文件的输出...

AppDataRoaming                   : Win32_FolderRedirectionHealth
Contacts                         : Win32_FolderRedirectionHealth
Desktop                          : Win32_FolderRedirectionHealth
Documents                        : Win32_FolderRedirectionHealth
Downloads                        : Win32_FolderRedirectionHealth
Favorites                        : Win32_FolderRedirectionHealth
HealthStatus                     : 3
LastAttemptedProfileDownloadTime : 
LastAttemptedProfileUploadTime   : 
LastBackgroundRegistryUploadTime : 
LastDownloadTime                 : 
LastUploadTime                   : 
LastUseTime                      : 2021-11-08 12:02:02 PM
Links                            : Win32_FolderRedirectionHealth
Loaded                           : True
LocalPath                        : C:\Users\[MyUserName]
Music                            : Win32_FolderRedirectionHealth
Pictures                         : Win32_FolderRedirectionHealth
RefCount                         : 
RoamingConfigured                : False
RoamingPath                      : 
RoamingPreference                : 
SavedGames                       : Win32_FolderRedirectionHealth
Searches                         : Win32_FolderRedirectionHealth
SID                              : S-1-5-[MySID]
Special                          : False
StartMenu                        : Win32_FolderRedirectionHealth
Status                           : 0
Videos                           : Win32_FolderRedirectionHealth
PSComputerName                   : 

您可以通过 .LocalPath 将配置文件与您的帐户交叉引用,或者使用 SID 进行查找以获取准确的帐户。