Tobias Simetsreiter 2 年 前
コミット
f82ebedd59
1 ファイル変更27 行追加30 行削除
  1. 27 30
      bin/Get-LoggedinUser.ps1

+ 27 - 30
bin/Get-LoggedinUser.ps1

@@ -1,4 +1,4 @@
-    <#
+<#
         .SYNOPSIS
             Shows all the users currently logged in to specified or remote computers
     
@@ -55,35 +55,32 @@
     ************************************************************************
     #>
     
-    [cmdletbinding()]
-       param(
-       [String[]]$Computer = $env:COMPUTERNAME
-       )
+[cmdletbinding()]
+param(
+    [String[]]$Computer = $env:COMPUTERNAME
+)
     
-       ForEach ($Comp in $Computer) 
-       { 
-       If (-not (Test-Connection -ComputerName $comp -Quiet -Count 1 -ea silentlycontinue)) 
-       {
-       Write-Warning "$comp is Offline"; continue 
-       } 
-       $stringOutput = quser /server:$Comp 2>$null
-          If (!$stringOutput)
-          {
-          Write-Warning "Unable to retrieve quser info for `"$Comp`""
-          }
-          ForEach ($line in $stringOutput){
-             If ($line -match "logon time") 
-             {Continue}
+ForEach ($Comp in $Computer) { 
+    If (-not (Test-Connection -ComputerName $comp -Quiet -Count 1 -ea silentlycontinue)) {
+        Write-Warning "$comp is Offline"; continue 
+    } 
+    $stringOutput = quser /server:$Comp 2>$null
+    If (!$stringOutput) {
+        Write-Warning "Unable to retrieve quser info for `"$Comp`""
+    }
+    ForEach ($line in $stringOutput) {
+        If ($line -match "logon time") 
+        { Continue }
     
-             [PSCustomObject]@{
-              ComputerName    = $Comp
-              Username        = $line.SubString(1, 20).Trim()
-              SessionName     = $line.SubString(23, 17).Trim()
-              ID             = $line.SubString(42, 2).Trim()
-              State           = $line.SubString(46, 6).Trim()
-              #Idle           = $line.SubString(54, 9).Trim().Replace('+', '.')
-              #LogonTime      = [datetime]$line.SubString(65)
-              }
+        [PSCustomObject]@{
+            ComputerName = $Comp
+            Username     = $line.SubString(1, 20).Trim()
+            SessionName  = $line.SubString(23, 17).Trim()
+            ID           = $line.SubString(42, 2).Trim()
+            State        = $line.SubString(46, 6).Trim()
+            #Idle           = $line.SubString(54, 9).Trim().Replace('+', '.')
+            #LogonTime      = [datetime]$line.SubString(65)
+        }
               
-          } 
-       } 
+    } 
+}