Get-LoggedinUser.ps1 580 B

1234567891011121314151617181920
  1. $stringOutput = quser 2>$null
  2. If (!$stringOutput) {
  3. Write-Warning "Unable to retrieve quser info for `"$Comp`""
  4. }
  5. $out = (($stringOutput -split "\n" -replace "SESSIONNAME", "") -replace "rdp-tcp#[0-9]+", "") -replace '\s\s+', ';'| convertfrom-csv -Delimiter ';'
  6. $out | ForEach-Object {
  7. If($_."IDLE TIME" -eq ".") {
  8. $_."IDLE TIME" =[TimeSpan]::Parse("0")
  9. return
  10. }
  11. If($_."IDLE TIME" -like "*:*") {
  12. $_."IDLE TIME" = [TimeSpan]::Parse($_."IDLE TIME")
  13. } else {
  14. $_."IDLE TIME" = [TimeSpan]::Parse("0:"+$_."IDLE TIME")
  15. }
  16. }
  17. $out