title: User Logon/Logoff Information using Powershell
body: <p>I want to be able to check a remote computer's user logon/logoff sessions and times and I have the following code that I got from stackoverflow, but I cannot figure out how to tell the script to check a remote computer:</p>
  
  <pre><code>$UserProperty = @{n="User";e={(New-Object System.Security.Principal.SecurityIdentifier  
  $_.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])}}
  $TypeProperty = @{n="Action";e={if($_.EventID -eq 7001) {"Logon"} else {"Logoff"}}}
  $TimeProeprty = @{n="Time";e={$_.TimeGenerated}}
  
  Get-EventLog System -Source Microsoft-Windows-Winlogon | select $UserProperty,$TypeProperty,$TimeProeprty
  </code></pre>
  
  <p>I did do throw in a $Computername variable and a Foreach loop statment like in the following to try and get it to run on a remote computer, but it keeps checking the local system that I am on, not the remote system:</p>
  
  <pre><code>$Computername = Read-Host "Enter Computername Here"
  
  Foreach $Computer in $Computername
  
      {
          $UserProperty = @{n="User";e={(New-Object System.Security.Principal.SecurityIdentifier $_.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])}}
          $TypeProperty = @{n="Action";e={if($_.EventID -eq 7001) {"Logon"} else {"Logoff"}}}
          $TimeProeprty = @{n="Time";e={$_.TimeGenerated}}
  
          Get-EventLog System -Source Microsoft-Windows-Winlogon | select $UserProperty,$TypeProperty,$TimeProeprty
      }
  </code></pre>