1

I need to generate a report that shows the guest account is disabled for a given list of computers.

How can I use net user, powershell, or any other commonly used tool for this purpose?

3 Answers3

2

Here's a little PowerShell function to check for this.

function Test-LocalAccountDisabled
{
    param (
        [string]
        $AccountName = 'Guest',
        [string[]]
        $ComputerName = $env:COMPUTERNAME
    )

    $AccountDisable=0x0002
    foreach ($Computer in $ComputerName)
    {
        [ADSI]$Guest="WinNT://$Computer/$AccountName,User"
        if ($Guest -ne $null)
        {
            New-Object PSObject -Property @{
                Disabled = ($Guest.UserFlags.Value -band $AccountDisable) -as [boolean]
                AccountName = $AccountName
                ComputerName = $Computer
            }
        }
        else
        {
            Write-Error "Unable to find $AccountName on $Computer."
        }
    }
}

If you have a list of computers in a text file separated by line breaks, you could do something like

Test-LocalAccountDisabled -ComputerName (get-content computers.txt)
1

PowerShell is probably the easiest way:

foreach ( $computer in (Get-Content computers.txt) ) {
  Get-WmiObject Win32_UserAccount -Computer $computer -Filter "Name = 'guest'" `
    | Select-Object __Server, Disabled
}

Using wmic in batch is ugly, but will work as well:

set query=useraccount where name^^="guest" get disabled

for /f %c in ('computers.txt') do (
  for /f "delims== tokens=2" %a in ('wmic /node:%c %query% /value') do (
    echo %c %a
  )
)
Ansgar Wiechers
  • 4,267
  • 2
  • 19
  • 26
0

A Powershell script with something like this should do the trick:

$Servers = Get-Content "C:\Path\To\File\With\Servers.txt"

foreach ($Server in $Servers)
{
    Get-WmiObject Win32_UserAccount -computername $Server -filter "LocalAccount=True AND` 
    Name='Guest'" | Select-Object Domain,Name,Disabled
}

This will read in a list of server names from a text file, and loop through them displaying an entry for each disabled guest account. If you take out AND Name=Guest, it will show you all disabled accounts on each machine.

Steve G
  • 231