Inventaire des sessions RDP de tout l’environnement
Fonction ? garder dans un coin :
Function Get-RDPSession { [cmdletbinding(DefaultParameterSetName = 'session',ConfirmImpact = 'low')] Param( [Parameter(Mandatory = $True,Position = 0,ValueFromPipeline = $True)] [string[]]$name) Begin {$report = @()} Process { foreach ($computer in $name) { write-host Checking $computer. if ( Test-Connection svc -ErrorAction SilentlyContinue -Count 1 ) { $sessions = query session /server:$computer 1..($sessions.count -1) | % { $temp = "" | Select Computer,SessionName, Username, Id, State, Type, Device $temp.Computer = $computer $temp.SessionName = $sessions[$_].Substring(1,18).Trim() $temp.Username = $sessions[$_].Substring(19,20).Trim() $temp.Id = $sessions[$_].Substring(39,9).Trim() $temp.State = $sessions[$_].Substring(48,8).Trim() $temp.Type = $sessions[$_].Substring(56,12).Trim() $temp.Device = $sessions[$_].Substring(68).Trim() $report += $temp } } } } End {$report} }
Exemple d’utilisation :
# Get-RDPSession -name svctxpd01 -ErrorAction silentlycontinue
Dans le cadre d’un AD, et en s?lectionnant que certains serveurs :
import-module activedirectory Get-RDPSession -name (get-adcomputer -Filter 'Name -like "VM_DESK*"' | select -ExpandProperty name ) | Out-GridView
Tout l’AD :
Get-RDPSession -name (get-adcomputer -Filter * | select -ExpandProperty name ) | Out-GridView
Un autre AD que l’AD principal:
Get-RDPSession -name (Get-ADComputer -Server DC_AUTRE_DOMAINE -filter 'name -like "*"' | select -ExpandProperty name ) | Out-GridView
Bref… que du bonheur !!!
1 commentaire