Hello,
Sorry if this is a double post, but once I add a new email address, it won’t index it correctly unless I add a new email address.
$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 -CaseSensitive "[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 } 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 -CaseSensitive "[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 -CaseSensitive "$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++) { $Index_Plus_One = $Index + 1; $Email = ($List_of_Users[$Index]) -creplace '^[^=]*=', '' $Re_Index = "$Index_Plus_One" + "=" +$Email $Read_INI = $Read_INI | Where-Object {$_ -ne $List_of_Users[$Index]} $Read_INI[$Users - 1] += "`r`n$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" }