Skript, mis kuvab kasutajad ja grupid

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

Pikkem varjant

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

$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 ==

# Skript väljastab kasutajad ja gruppid kuhu nad kuuluvad.

$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='Gruppid';e={$groups -join ' & '}
    }
 }