-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudit-textlogs.ps1
43 lines (38 loc) · 1.67 KB
/
Audit-textlogs.ps1
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
function Audit-Textlogs
{
param(
[string]$ComputerName = 'localhost',
[datetime]$StartTimestamp=((Get-Date).adddays(-1)),
[datetime]$EndTimestamp=(Get-Date),
[string]$LogFileExtension = 'log'
)
## Define the drives to look for log files if local or the shares to look for when remote
if ($ComputerName -eq 'localhost') {
$Locations = (Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType = '3'").DeviceID
} else {
## Enumerate all shares
$Shares = Get-CimInstance -ComputerName $ComputerName -Class Win32_Share | where { $_.Path -match '^\w{1}:\\$' }
[System.Collections.ArrayList]$Locations = @()
foreach ($Share in $Shares) {
$Share = "\\$ComputerName\$($Share.Name)"
if (!(Test-Path $Share)) {
Write-Warning "Unable to access the '$Share' share on '$Computername'"
} else {
$Locations.Add($Share) | Out-Null
}
}
}
## Build the hashtable to perform splatting on Get-ChildItem
$GciParams = @{
Path = $Locations
Filter = "*.$LogFileExtension"
Recurse = $true
Force = $true
ErrorAction = 'SilentlyContinue'
File = $true
}
## Build the Where-Object scriptblock on a separate line due to it's length
$WhereFilter = {($_.LastWriteTime -ge $StartTimestamp) -and ($_.LastWriteTime -le $EndTimestamp) -and ($_.Length -ne 0)}
## Find all interesting log files
(Get-ChildItem @GciParams | Where-Object $WhereFilter).FullName
}