Last active
March 11, 2020 16:37
-
-
Save zaneGittins/f28b70bae128132f8187a281ef63f533 to your computer and use it in GitHub Desktop.
Teams Unlock/Lock
This file contains 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
#Requires -Version 5.0 | |
<# | |
.SYNOPSIS | |
Teams Unlock/Lock Events - Gets unlock and lock events from Microsoft Teams logs file. | |
Can be used to trace interactive logins. | |
.PARAMETER TargetUser | |
User to get logs for | |
.NOTES | |
Author: Zane Gittins | |
Last Updated: 3/11/2020 | |
#> | |
param ( | |
[Parameter(Mandatory=$true, Position=0)][string]$TargetUser, | |
[Parameter(Mandatory=$false, Position=1)][string]$CSVPath = "Output.csv" | |
) | |
class Record { | |
[string]$Timestamp = "" | |
[string]$Message = "" | |
} | |
function Get-TeamsData { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true, Position=0)][string]$LogPath | |
) | |
$TeamsLogContent = Get-Content $LogPath | |
$Records = @() | |
for ($i = 0; $i -le $TeamsLogContent.Length; $i++ ) { | |
$NewRecord = [Record]::new() | |
$RecordArray = $TeamsLogContent[$i] -split "--" | |
$NewRecord.Timestamp = $RecordArray[0] | |
$NewRecord.Message = $RecordArray[2] | |
if($NewRecord.Message -like "*locked*") { | |
$Records += $NewRecord | |
} | |
[int]$Complete = ($i/$TeamsLogContent.Length) * 100 | |
Write-Progress -Activity "Parsing Logs" -Status "$Complete% Complete:" -PercentComplete $Complete | |
} | |
return $Records | |
} | |
$Path = "C:\Users\" + $TargetUser + "\AppData\Roaming\Microsoft\Teams\logs.txt" | |
$Records = Get-TeamsData -LogPath $Path | |
$Records | Export-Csv -Path $CSVPath -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment