【发布时间】:2018-11-05 15:09:16
【问题描述】:
我在 Windows server 2008 R2 上,我需要提取本地配置文件列表,因此我使用 Powershell 查看注册表并获得我想要的:
$path = 'Registry::HKey_Local_Machine\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\*'
$items = Get-ItemProperty -path $path
Foreach ($item in $items) {
$objUser = New-Object
System.Security.Principal.SecurityIdentifier($item.PSChildName)
$objName = $objUser.Translate([System.Security.Principal.NTAccount])
$item.PSChildName = $objName.value
}
echo $items | Select-Object -Property PSChildName | Export-Csv
C:\scripts\PSScripts\UserProfile.csv -Encoding UTF8
它在另一台使用 Windows Server 2012 R2 的机器上工作,但在这里我遇到了很多错误,但总是一样的:
使用“1”个参数调用“翻译”的异常:“部分或全部 身份参考无法翻译。”在 C:\scripts\PSScripts\users_profile.ps1:5 char:34 + $objName = $objUser.Translate
.csv 文件已创建,但存在问题,例如显示多次的个人资料,如下所示:
域\用户 1 域\用户 2 域\用户 3 域\用户 3 域\用户 4 域\用户 5 域\用户 5 域\用户 5 域\用户 6WS2008 和 WS2012 之间是否存在可能导致此问题的差异?还是别的什么?
【问题讨论】:
-
我无权访问那些操作系统,所以这是一种不同的方法……您尝试过 WMI 类了吗?这个
Get-CimInstance -ClassName 'Win32_UserProfile' -ComputerName 'LocalHost'似乎在win7ps5.1 上运行得很好。此外,WMI 对象调用Get-WmiObject -Class 'Win32_UserProfile' -ComputerName 'LocalHost'有一个.Delete()方法,可以清理几乎所有内容。 -
也许我需要导入一个模块,或者它不适用于 WS2008,但是当我尝试
Get-CimInstance时出现此错误:“Get-CimInstance”一词未被识别为cmdlet、函数、脚本文件或可运行程序的名称。 而另一个命令没有提供我需要的 PSChildName -
如果 CIM cmdlet 不工作,那么您运行的是旧版本的 PoSh。请改用
Get-WMIObject。
标签: powershell csv registry