Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_log_ip_mac.ps

(view source code of login_log_ip_mac.ps as plain text)

  1. $MACAddress = ( Get-NetAdapter | Where-Object -Property Status -eq Up | Select-Object -First 1 ).MacAddress
  2. $IPAddress  = ( Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet | Select-Object -First 1 ).IPAddress
  3. $Today      = Get-Date -Format 'yyyyMMdd'
  4. # Append IP and MAC adresses to log file
  5. "$IPAddress,$MACAddress\n" | Out-File -FilePath "\\Server\Logs\$Today\$Env:UserName.log" -Encoding ASCII -Append

page last uploaded: 2021-01-27, 16:12