Come generare ed esportare il report di tutti gli utenti connessi

Spesso, gli amministratori desiderano conoscere l’elenco di tutti gli utenti attualmente connessi. È possibile ottenere questa informazione solo usando degli script di Windows PowerShell. Tuttavia, la creazione dello script e la necessità di modificarlo ogni volta per generare un report in un formato specifico rendono questo processo particolarmente noioso. Una soluzione di auditing AD come ADAudit Plus può aiutare gli amministratori a ottenere questo report in un baleno. Di seguito è riportato un confronto tra le procedure per ottenere il report di tutti gli utenti AD connessi con Windows PowerShell e ADAudit Plus:

PowerShell

Procedura per ottenere tutti gli utenti connessi usando PowerShell:

  • Identificare il dominio da cui desideri recuperare il report.
  • Identificare gli attributi LDAP di cui necessiti per recuperare il report.
  • Identificare il DC primario per recuperare il report.
  • Specificare i parametri sopra elencati nello script fornito in basso e compilarlo.
  • Eseguirlo in Windows PowerShell.
  • Il report sarà esportato nel formato file con estensione .psm.
  • Per ottenere il report in un formato differente, modificare opportunamente lo script.

Script di esempio per Windows PowerShell

function Get-Execute it in Windows PowerShell.UserLogon {
[CmdletBinding()]
param
(
[Parameter ()]
[String]$Computer,
[Parameter ()]
[String]$OU,
[Parameter ()]
[Switch]$All
)
$ErrorActionPreference="SilentlyContinue"
$result=@()
If ($Computer) {
Invoke-Command -ComputerName $Computer -ScriptBlock {quser} | Select-Object -Skip 1 | Foreach-Object {
$b=$_.trim() -replace '\s+',' ' -replace '>','' -split '\s'
 
If ($b[2] -like 'Disc*') {
 
$array= ([ordered]@{
'User' = $b[0]
'Computer' = $Computer
'Date' = $b[4]
'Time' = $b[5..6] -join ' '
})
$result+=New-Object -TypeName PSCustomObject -Property $array
}
else {
$array= ([ordered]@{
'User' = $b[0]
'Computer' = $Computer
'Date' = $b[5]
'Time' = $b[6..7] -join ' '
})
 
$result+=New-Object -TypeName PSCustomObject -Property $array
 
}
}
}
 
If ($OU) {
 
$comp=Get-ADComputer -Filter * -SearchBase "$OU" -Properties operatingsystem
 
$count=$comp.count
 
If ($count -gt 20) {
 
Write-Warning "Search $count computers. This may take some time ... About 4 seconds for each computer"
 
}
 
foreach ($u in $comp) {
 
Invoke-Command -ComputerName $u.Name -ScriptBlock {quser} | Select-Object -Skip 1 | ForEach-Object {
 
$a=$_.trim() -replace '\s+',' ' -replace '>','' -split '\s'
 
If ($a[2] -like '*Disc*') {
 
$array= ([ordered]@{
'User' = $a[0]
'Computer' = $u.Name
'Date' = $a[4]
'Time' = $a[5..6] -join ' '
})
 
$result+=New-Object -TypeName PSCustomObject -Property $array
}
 
else {
 
$array= ([ordered]@{
'User' = $a[0]
'Computer' = $u.Name
'Date' = $a[5]
'Time' = $a[6..7] -join ' '
})
 
$result+=New-Object -TypeName PSCustomObject -Property $array
}
 
}
 
}
 
}
 
If ($All) {
 
$comp=Get-ADComputer -Filter * -Properties operatingsystem
 
$count=$comp.count
 
If ($count -gt 20) {
 
Write-Warning "Search $count computers. This may take some time ... About 4 seconds for each computer ..."
 
}
 
foreach ($u in $comp) {
 
Invoke-Command -ComputerName $u.Name -ScriptBlock {quser} | Select-Object -Skip 1 | ForEach-Object {
 
$a=$_.trim() -replace '\s+',' ' -replace '>','' -split '\s'
 
If ($a[2] -like '*Disc*') {
 
$array= ([ordered]@{
'User' = $a[0]
'Computer' = $u.Name
'Date' = $a[4]
'Time' = $a[5..6] -join ' '
})
 
$result+=New-Object -TypeName PSCustomObject -Property $array
 
}
 
else {
 
$array= ([ordered]@{
'User' = $a[0]
'Computer' = $u.Name
'Date' = $a[5]
'Time' = $a[6..7] -join ' '
})
 
$result+=New-Object -TypeName PSCustomObject -Property $array
 
}
 
}
 
}
}
Write-Output $result
}

 Copied
Fare clic per copiare l’intero script

ADAudit Plus

Per ottenere il report,

  • Accedere alla console web di ADAudit Plus come amministratore.
  • Navigare fino alla scheda Report. Fare clic sulla sezione Accessi utenti dal pannello di sinistra e selezionare l’opzione Report accessi utenti.
  • Selezionare Esporta come per esportare il report in uno qualsiasi dei formati preferiti (CSV, PDF, HTML, CSVDE e XLSX).

Screenshot

powershell-get-logged-on-user-1
 

Di seguito sono elencate le limitazioni per ottenere un report di tutti gli utenti AD connessi mediante strumenti nativi come Windows PowerShell:

  • Lo script può essere eseguito solo da computer che dispongono del ruolo Active Directory Domain Services.
  • Si incontrano difficoltà nel cambio di formato della data e nell’applicare fusi orari diversi ai risultati della data.
  • Si incontrano difficoltà nell’esportare il report in un formato file diverso da CSV.
  • L'applicazione di molteplici filtri, come UO o "Il nome utente inizia con", aumenterà la complessità della query LDAP.

ADAudit Plus genererà il report scansionando in automatico tutti i controller di dominio presenti nel domino per estrarre l’elenco degli utenti connessi, mostrandolo tramite un’interfaccia utente semplice e dal design intuitivo.

  • Script PowerShell e semplificazione del controllo delle modifiche AD con ADAudit Plus.
  •  
  • Facendo clic su “Inizia subito la tua prova gratuita” accetti l’elaborazione dei tuoi dati personali in base all’informativa sulla privacy.
  •  
  • Grazie per lo scaricamento!
  • Il tuo scaricamento dovrebbe iniziare automaticamente tra 15 secondi. Altrimenti, fai clic qui per scaricare manualmente.

Risorse correlate