Skript, mis kuvab kasutajad ja grupid

From ICO wiki
Revision as of 10:43, 27 May 2011 by Kkalme (talk | contribs)
Jump to navigationJump to search

Skript kuvab kõik kasutajad ja grupid kuhu kasutajad kuuluvad.

Pikkem varjant

$computer = [ADSI]("WinNT://arvuti nimi,computer")
$Users = $computer.psbase.children |where{$_.psbase.schemaclassname -eq "User"}
$grupid = $computer.psbase.children |where{$_.psbase.schemaclassname -eq "Group"}

foreach ($member in $Users.psbase.syncroot) 
{ 
    write-host $member.Name
    
   foreach ($grupp in $grupid) 
    { 
        $olemas = $grupp.psbase.invoke("Members") | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
        if($olemas)
        { 
            foreach($x in $olemas)
            {
                if($x -eq $member.Name)
                {
                    Write-Host "-------"$grupp.Name
                }
            }
        }
    }
}


== Lühem varjant ==


$computer = [ADSI]"WinNT://$env:COMPUTERNAME"

$computer.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
   
    $groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
   
    $_ | Select-Object @{n='Kasutajad';e={$_.Name}},@{n='Grupid';e={$groups -join ' & '}
    }
 }