Unable to obtain status (Disable) of Local user

我与影子孤独终老i 提交于 2021-01-29 21:56:53

问题


I ‘m trying to obtain a list of Local Users with Group Membership and Disabled status. I had some success however could not get the corresponding Disable status of each local user. I’m using WMI in conjunction with ADSI to obtain a Disable Status of local users. The Disable Status property is not available with ADSI. Since, I’m a PS newbie any alternative options or explanation would be greatly appreciated. FYI: These are standalone servers not member servers

$adsi = [ADSI]"WinNT://$env:computername"
$user = $adsi.Children | where {$_.SchemaClassName -eq 'user'}
$user| Foreach-Object {
    $g1 = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
    $s1 = gwmi -ClassName Win32_UserAccount -Filter “LocalAccount = $true” | % { $_.Disabled}
    $_ | Select-Object  @{n='UserName';e={$_.Name}},
    @{n='Groups';e={$g1 -join ';'}},
    @{n='LastLogin';e={$_.LastLogin}},
    @{n='DisabledSatus';e={$s1 -join ''}}    
       }

Output:

UserName                        Groups                          LastLogin                       Disabled                        
--------                        ------                          ---------                       -----                         
Administrator                   Administrators                  6/5/2012 5:18:54 PM             OKOKDegradedOKOKOKOKOKOKDeg...
TestUser                Users               10/10/2013 7:11:22 PM       OKOKDegradedOKOKOKOKOKOKDeg..

回答1:


Two changes. I'd add this at the top of your ForEach-Object loop:

$currentuser = $_

And change the $s line to this:

$s1 = gwmi -ClassName Win32_UserAccount -Filter “LocalAccount = $true” | ? {$_.Name -eq $currentuser.Name} | % { $_.Disabled}


来源:https://stackoverflow.com/questions/24152530/unable-to-obtain-status-disable-of-local-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!