问候最令人惊叹的社区,
我正在尝试提出一个脚本,该脚本将列出PC上的所有配置文件。 我想要的列表示例:
Admin
JSmith
LGale
Mthinker
有没有人知道如何尝试获取信息或可以共享的代码段?
我看了网上,做了一些研究,还看了很多可用的脚本,但是当我需要的时候,什么都不是。
答案 0 :(得分:1)
您将要查询WMI的Win32_UserProfile
实例-每个配置文件都将链接到拥有该配置文件的用户的安全标识符,该安全标识符又可以转换为具有用户名的帐户对象:< / p>
v3 = document.getElementById("npo-registration-number");
flag3 = true;
if (v3.value == "") {
v3.style.borderColor = "red";
flag3 = false;
} else {
if (v3.value.length < 7){
v3.style.borderColor = "red";
flag3 = false;
}
else {
v3.style.borderColor = "green";
flag3 = true;
}
}
在我的计算机上(只有一个本地帐户)列出了以下内容:
Get-CimInstance win32_userprofile |ForEach-Object {
# Convert SID string to SecurityIdentifier object
$SID = $_.SID -as [System.Security.Principal.SecurityIdentifier]
try {
# Now we can resolve the actual account
$SID.Translate([System.Security.Principal.NTAccount]).Value
}
catch {
Write-Warning "Unable to translate SID '$($_.SID)' for profile at '$($_.LocalPath)' to account name"
}
}