Hello,
I asked this question yesterday, and I thought I got it working but it’s not. My first issue is that, when I enter a new email address, it adds it to the list, but it doesn’t number it. If I enter another email, it numbers the previous email correctly, but not the new one. Basically, it doesn’t number the latest email address.
I’m almost certain my function calls are not in the correct order, but I can’t figure it out.
I want it to number the email addresses when they’re created, not the next time a new email is added.
Example:
[1] Create new user
[2] Delete a user
[3] Add user to calender
[0] Exit menu
Please select an option and press ENTER: 1
Enter new employee’s account name: gps@company.com
[1] Create new user
[2] Delete a user
[3] Add user to calender
[0] Exit menu
It created gps@company.com, but didn’t number it
Please select an option and press ENTER: 1
Enter new employee’s account name: wcs@company.com
[1] Create new user
[2] Delete a user
[3] Add user to calender
[0] Exit menu
Please select an option and press ENTER: 0
It created wcss@company.com, but didn’t number it, it numbered gps@company.com
This is what this looks like now. Notice the number before gps, and no number before wcs. It added 1443 after I entered wcs.
1443=gps@company.com
wcs@company.com
$MenuChoice = $null While($MenuChoice -ne 0) { $INI_Location = '\\hqfs1\users\tantony\PowerShell\CalenderGroup\config.ini' $Read_INI = Get-Content $INI_Location $GroupCalendars = ($Read_INI | Select-String -Pattern "[GroupCalendars]" -SimpleMatch).LineNumber $Users = ($Read_INI | Select-String -CaseSensitive "[Users]" -SimpleMatch).LineNumber $Calender_Groups = ($Read_INI | Select-String -CaseSensitive "[MembersOf-1]" -SimpleMatch).LineNumber - 2 $Calender_Option = $Read_INI[$GroupCalendars..$Users] function Create_User { $New_User = Read-Host "Enter new employee's account name" $Read_INI[$Calender_Groups] += "`r`n$New_User" Reindex_Users $Read_INI | Set-Content $INI_Location -Force } function Delete_User { $Del_User = Read-Host "Enter the email you want to delete" $Read_INI | where {$_ -ne $Del_User} | Set-Content $INI_Location -Force } function Find_User_Index ([string]$email) { $E = ($Read_INI | Select-String -AllMatches "$email" -SimpleMatch) $E.ToString().Trim("=$email") } function Add_User_To_Calender { $Get_User = Read-Host "Enter email address of the employee to add" $Calender_Option $Get_Calender = Read-Host "Which calenders do you want to add" $Get_User "to?" $Calender = ($Calender_Option[$Get_Calender - 1]) $Start = ($Read_INI | Select-String -Pattern "[MembersOf-$Get_Calender]" -SimpleMatch).LineNumber $Next_Group = ($Read_INI[$Start..$Read_INI.Count] | Select-String -AllMatches "[Membersof" -SimpleMatch) | Select-Object -First 1 $End = ($Read_INI | Select-String -AllMatches "$Next_Group" -SimpleMatch).LineNumber - 2 $Line = $End - $Start $User = Find_User_Index $Get_User $Write = "$Line=$User" $Read_INI[$End] += "`r`n$Write" $Read_INI | Set-Content $INI_Location -Force } function Reindex_Users { $List_of_Users = $Read_INI[$Users..$Calender_Groups] For($Index=0; $Index -lt $List_of_Users.length; $Index++) { $Email = ($List_of_Users[$Index]) -creplace '^[^=]*=', '' $Index_Plus_One = $Index + 1 $Re_Index = "$Index_Plus_One=$Email" $Read_INI[$Index+$Users] = "" $Read_INI[$Index+$Users] += $Re_Index } #$Read_INI | Set-Content $INI_Location -Force } switch ($MenuChoice) { 1 {Create_User} 2 {Delete_User} 3 {Add_User_To_Calender} } Write-Host "[1]`tCreate new user" Write-Host "[2]`tDelete a user" Write-Host "[3]`tAdd user to calender" Write-Host "[0]`tExit menu" $MenuChoice = Read-Host "`nPlease select an option and press ENTER" Write-Host "`n" }
Thank you,
Tony