-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathLogonLogoff.ps1
More file actions
48 lines (44 loc) · 1.49 KB
/
LogonLogoff.ps1
File metadata and controls
48 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<#
.SYNOPSIS
Logon Reporting
.DESCRIPTION
This script will report the computername, username, IP address, and date/time to a central log file.
.PARAMETER LogFile
A description of the LogFile parameter.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.142
Created on: 10/22/2018 10:13 AM
Created by: Mick Pletcher
Filename: LogonReport.ps1
===========================================================================
#>
[CmdletBinding()]
param
(
[ValidateNotNullOrEmpty()]
[string]$LogFile = 'LogonReport.csv'
)
$Entries = @()
$IPv4 = foreach ($ip in (ipconfig) -like '*IPv4*') {($ip -split ' : ')[-1]}
$DT = Get-Date
foreach ($IP in $IPv4) {
$object = New-Object -TypeName System.Management.Automation.PSObject
$object | Add-Member -MemberType NoteProperty -Name ComputerName -Value $env:COMPUTERNAME
$object | Add-Member -MemberType NoteProperty -Name UserName -Value $env:USERNAME
$object | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IP
$object | Add-Member -MemberType NoteProperty -Name DateTime -Value (Get-Date)
$object
$Entries += $object
}
foreach ($Entry in $Entries) {
Do {
Try {
Export-Csv -InputObject $Entry -Path $LogFile -Encoding UTF8 -NoTypeInformation -NoClobber -Append
$Success = $true
} Catch {
$Success = $false
Start-Sleep -Seconds 1
}
} while ($Success -eq $false)
}