AD_user scripts
This commit is contained in:
44
Scripts/powershell/Get-ADUserGroups.ps1
Normal file
44
Scripts/powershell/Get-ADUserGroups.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Kilistázza egy megadott AD felhasználó összes csoporttagságát.
|
||||
#>
|
||||
|
||||
param (
|
||||
[Parameter(Mandatory=$true, HelpMessage="Add meg a felhasználó nevét (sAMAccountName)")]
|
||||
[string]$UserName
|
||||
)
|
||||
|
||||
# Ellenőrizzük, hogy az Active Directory modul elérhető-e
|
||||
if (!(Get-Module -ListAvailable ActiveDirectory)) {
|
||||
Write-Error "Az 'ActiveDirectory' modul nem található. Kérlek telepítsd az RSAT eszközt!"
|
||||
return
|
||||
}
|
||||
|
||||
# Importáljuk a modult, ha még nincs betöltve
|
||||
if (!(Get-Module ActiveDirectory)) {
|
||||
Import-Module ActiveDirectory
|
||||
}
|
||||
|
||||
try {
|
||||
# Felhasználó ellenőrzése
|
||||
$user = Get-ADUser -Identity $UserName -ErrorAction Stop
|
||||
|
||||
Write-Host "`nLekérdezés folyamatban: $($user.Name) ($UserName)..." -ForegroundColor Cyan
|
||||
|
||||
# Csoportok lekérése (Get-ADPrincipalGroupMembership kezeli a rekurziót is)
|
||||
$groups = Get-ADPrincipalGroupMembership -Identity $UserName | Select-Object Name, Category, GroupScope, DistinguishedName | Sort-Object Name
|
||||
|
||||
if ($groups) {
|
||||
Write-Host "Talált csoportok száma: $($groups.Count)`n" -ForegroundColor Green
|
||||
$groups | Format-Table Name, Category, GroupScope -AutoSize
|
||||
} else {
|
||||
Write-Host "A felhasználó egyetlen csoportnak sem tagja (kivéve a Primary Group-ot)." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
} catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
|
||||
Write-Host "HIBA: A(z) '$UserName' nevű felhasználó nem található az Active Directory-ban!" -ForegroundColor Red
|
||||
} catch {
|
||||
Write-Host "Váratlan hiba történt: $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host "`nKész." -ForegroundColor Gray
|
||||
Reference in New Issue
Block a user