AD_user scripts
This commit is contained in:
97
Scripts/powershell/Get-ADUserDetails.ps1
Normal file
97
Scripts/powershell/Get-ADUserDetails.ps1
Normal file
@@ -0,0 +1,97 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Reszletes informaciokat kerdez le egy AD felhasznalorol (Allgemein, Adresse, Organisation fulek).
|
||||
#>
|
||||
|
||||
param (
|
||||
[Parameter(Mandatory=$true, HelpMessage="Add meg a felhasznalo nevet (sAMAccountName)")]
|
||||
[string]$UserName
|
||||
)
|
||||
|
||||
# Ellenorizzuk, hogy az Active Directory modul elerheto-e
|
||||
if (!(Get-Module -ListAvailable ActiveDirectory)) {
|
||||
Write-Error "Az 'ActiveDirectory' modul nem talalhato. Kerlek telepitsd az RSAT eszközt!"
|
||||
return
|
||||
}
|
||||
|
||||
# Importaljuk a modult, ha meg nincs betoltve
|
||||
if (!(Get-Module ActiveDirectory)) {
|
||||
Import-Module ActiveDirectory
|
||||
}
|
||||
|
||||
try {
|
||||
# Az osszes tulajdonsag lekerese
|
||||
$user = Get-ADUser -Identity $UserName -Properties * -ErrorAction Stop
|
||||
|
||||
Write-Host "`n========================================================" -ForegroundColor Cyan
|
||||
Write-Host " AD FELHASZNALOI ADATOK: $($user.DisplayName) " -ForegroundColor Cyan
|
||||
Write-Host "========================================================`n" -ForegroundColor Cyan
|
||||
|
||||
# --- ALLGEMEIN (Altalanos) ---
|
||||
Write-Host "[ Allgemein / Altalanos ]" -ForegroundColor Yellow
|
||||
$allgemein = [PSCustomObject]@{
|
||||
"Vorname (Keresztnev)" = $user.GivenName
|
||||
"Nachname (Vezeteknev)" = $user.Surname
|
||||
"Anzeigename" = $user.DisplayName
|
||||
"Beschreibung" = $user.Description
|
||||
"Buero (Iroda)" = $user.Office
|
||||
"Telefon" = $user.TelephoneNumber
|
||||
"E-Mail" = $user.EmailAddress
|
||||
"Webseite" = $user.wWWHomePage
|
||||
}
|
||||
$allgemein | Format-List
|
||||
Write-Host "--------------------------------------------------------" -ForegroundColor Gray
|
||||
|
||||
# --- ADRESSE (Cim) ---
|
||||
Write-Host "[ Adresse / Cim ]" -ForegroundColor Yellow
|
||||
$adresse = [PSCustomObject]@{
|
||||
"Strasse" = $user.StreetAddress
|
||||
"Postfach" = $user.PostOfficeBox
|
||||
"PLZ (Iranyitoszam)" = $user.PostalCode
|
||||
"Stadt (Varos)" = $user.L
|
||||
"Bundesland (Megye)" = $user.St
|
||||
"Land" = $user.CO
|
||||
}
|
||||
$adresse | Format-List
|
||||
Write-Host "--------------------------------------------------------" -ForegroundColor Gray
|
||||
|
||||
# --- ORGANISATION (Szervezet) ---
|
||||
Write-Host "[ Organisation / Szervezet ]" -ForegroundColor Yellow
|
||||
|
||||
# Manager nevenek feloldasa DN-bol
|
||||
$managerName = "Nincs megadva"
|
||||
if ($user.Manager) {
|
||||
try {
|
||||
$managerName = (Get-ADUser -Identity $user.Manager).Name
|
||||
} catch {
|
||||
$managerName = $user.Manager # Ha nem sikerul feloldani, marad a DN
|
||||
}
|
||||
}
|
||||
|
||||
$org = [PSCustomObject]@{
|
||||
"Titel (Beosztas)" = $user.Title
|
||||
"Abteilung (Osztaly)" = $user.Department
|
||||
"Firma (Ceg)" = $user.Company
|
||||
"Vorgesetzter (Fonok)" = $managerName
|
||||
}
|
||||
$org | Format-List
|
||||
Write-Host "--------------------------------------------------------" -ForegroundColor Gray
|
||||
|
||||
# --- CSOPORTOK LISTAJA ---
|
||||
$groups = Get-ADPrincipalGroupMembership -Identity $UserName | Select-Object -ExpandProperty Name | Sort-Object
|
||||
Write-Host "[ Gruppen / Csoporttagsagok ($($groups.Count) db) ]" -ForegroundColor Yellow
|
||||
if ($groups) {
|
||||
foreach ($group in $groups) {
|
||||
Write-Host "- $group"
|
||||
}
|
||||
} else {
|
||||
Write-Host "Csak a Domain Users tagja."
|
||||
}
|
||||
|
||||
} catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
|
||||
Write-Host "HIBA: A(z) '$UserName' nevu felhasznalo nem talalhato!" -ForegroundColor Red
|
||||
} catch {
|
||||
Write-Host "Varatlan hiba tortent: $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host "`n========================================================`n" -ForegroundColor Cyan
|
||||
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