Last active
November 28, 2023 20:59
-
-
Save malteb247/b8e78cf8c10b43c268554cdd36281a08 to your computer and use it in GitHub Desktop.
MS teams attendee log to jira user name list
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
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[string] | |
$InputFile | |
) | |
function Get-Participants ($file) { | |
$allLines = Get-Content -Path $InputFile | |
$participants = @() | |
$found = $false | |
foreach ($line in $allLines) { | |
if ($found) { | |
if ($line -eq "") { | |
break | |
} | |
$mailAddress = Get-MailAddress($line) | |
$userName = ConvertTo-UserName($mailAddress) | |
$participants += $userName | |
} | |
if (!$found -and $line -like "Name*First Join*") { | |
$found = $true | |
} | |
} | |
return $participants | |
} | |
function Get-MailAddress ($text) { | |
$fields = $text -split "\t" | |
return $fields[4] | |
} | |
function ConvertTo-UserName ($MailAddress) { | |
# no regex today | |
$NameAndDomain = $MailAddress -split "@" | |
$FirstNameAndLastName = $NameAndDomain[0] -split "\." | |
$UserName = $FirstNameAndLastName[0][0] | |
$UserName += $FirstNameAndLastName[1] | |
return "[~$($UserName.ToLowerInvariant())]" | |
} | |
#$UserNameTestCases = @( | |
# @{"MailAddress" = "Marco.Checker@mycompany.com"; "UserName" = "[~mchecker]" }, | |
# @{"MailAddress" = "Lena-Maria.Becker@mycompany.com"; "UserName" = "[~lbecker]" }, | |
# @{"MailAddress" = "Annette.Droste-Hülshoff@mycompany.com"; "UserName" = "[~adroste-hülshoff]" } | |
#) | |
# | |
#Describe "ConvertTo-UserName" { | |
# It "should convert <MailAddress> into <UserName>" -TestCases $UserNameTestCases { | |
# param($MailAddress, $UserName) | |
# ConvertTo-UserName $MailAddress | Should Be $UserName | |
# } | |
#} | |
# | |
#Describe "Get-MailAddress" { | |
# It "should parse the mail address from a csv row" { | |
# Get-MailAddress "Marco Checker 11/08/23, 9:28:57 AM 11/08/23, 11:37:37 AM 2h 8m 39s Marco.Checker@mycompany.com Marco.checker@mycompany.com Organizer" | Should Be "Marco.Checker@mycompany.com" | |
# } | |
#} | |
if ($null -eq $InputFile -or $InputFile.Trim().Length -eq 0) { | |
Add-Type -AssemblyName System.Windows.Forms | |
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ | |
InitialDirectory = [Environment]::GetFolderPath('Desktop') | |
Filter = "CSV (*.csv)|*.csv|All Files|*.*" | |
Title = "Please select the attendance report file" | |
Multiselect = $false | |
} | |
if ( "OK" -eq $FileBrowser.ShowDialog() ) { | |
$InputFile = $FileBrowser.FileName | |
} | |
else { | |
exit 1 | |
} | |
} | |
$participants = Get-Participants $InputFile | Sort-Object | |
if ( $null -eq $(Get-Command -CommandType Cmdlet "set-clipboard")) { | |
Write-Host "If Set-Clipboard woul be available, the list is added to the clipboard." | |
Write-Host $participants | |
} | |
else { | |
Set-Clipboard $($participants -join "`n") | |
Write-Host "List copied to clipboard." | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replaced VB dialog with .net OpenFileDialog.