Last active
September 15, 2016 20:37
-
-
Save mortenya/1b70c70212554d1e5a67cccbca4a840b to your computer and use it in GitHub Desktop.
These are some scripts I've used to parse unstructured output from GroupWise to get useful info. Parse-GWCheckLog.ps1 was the first one I wrote, and it might be a little fat. A good learning point though.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-Location C:\GWCheck | |
Get-ChildItem . | % { | |
Get-Content $_.FullName -PipelineVariable log | % { | |
if ($log -match "\S*Checking user =*\S.([^\s]+)|[\s]+(\d+).\S*kbytes*\S") | |
{ | |
$matches[0] | Out-File -Append .\gwcheck.txt #"" | select @{n='User';e={$matches[1]}},@{n='Size';e={$matches[2]}} | |
} | |
} | |
} | |
$foo = Get-Content .\gwcheck.txt | |
$foo = $foo -replace "Checking user = ","" # leaves just the username | |
$foo = $foo -replace " kbytes","" # leaves just the size | |
$foo = $foo -replace '\s+','' # removes extra whitespace | |
$foo | Set-Content .\gwcheck.txt | |
$file = Get-Content .\gwcheck.txt | |
for($i = 0; $i -lt $file.Count; $i++) | |
{ | |
$line = $file[$i] | |
if ($line.StartsWith('0') -or | |
$line.StartsWith('1') -or | |
$line.StartsWith('2') -or | |
$line.StartsWith('3') -or | |
$line.StartsWith('4') -or | |
$line.StartsWith('5') -or | |
$line.StartsWith('6') -or | |
$line.StartsWith('7') -or | |
$line.StartsWith('8') -or | |
$line.StartsWith('9')) | |
{ | |
Add-Content -Value "$($file[$i-1]),$($line)" -Path .\gwcheck-cleaned.txt | |
} | |
} | |
Remove-Item .\gwcheck.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-Location "$(Split-Path $PSCommandPath)" | |
# Audit report for user ([^\s]+\w) | |
# \sLast login time - (\d+\/\d+\/\d+) | |
# \sLast activity time - (\d+\/\d+\/\d+) | |
# \s(Limited|Full) client license (global) | |
Get-ChildItem . | % { | |
Get-Content $_.FullName -PipelineVariable log | % { | |
if ($log -match "(Audit report for user \(([^\s]+\w)|\sLast login time - (\d+\/\d+\/\d+)|\sLast activity time - (\d+\/\d+\/\d+)|\s(Limited|Full|inactive) client license)") | |
{ | |
#$matches[0]#[0] | Out-File -Append .\gwcheck.txt | |
#$matches[1] | |
$matches[2] | Out-File -Append .\gwcheck.txt | |
$matches[3] | Out-File -Append .\gwcheck.txt | |
$matches[4] | Out-File -Append .\gwcheck.txt | |
$matches[5] | Out-File -Append .\gwcheck.txt | |
} | |
} | |
} | |
$file = Get-Content .\gwcheck.txt | |
Add-Content -Value "Username,Last Login,Last Activity,License" -Path .\gwusers.csv | |
while ($file.Length -ge 4) | |
{ | |
Add-Content -Value "$($file[0]),$($file[1]),$($file[2]),$($file[3])" -Path .\gwusers.csv | |
$file = $file[4..$($file.Length)] | |
} | |
Remove-Item .\gwcheck.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment