Bunu kendim için yaptım ama hadi dedim kendimize saklamayalım, paylaşayım dedim.Güle güle kullanın...
KOD İÇERİĞİ :
Kod: Tümünü seç
# ============================================================
# Address Book Application
# System : Windows 11
# ============================================================
$AddressBookFile = Join-Path $PSScriptRoot "address_book.dat"
function Show-Header {
Clear-Host
Write-Host "============================================" -ForegroundColor Blue
Write-Host " Address Book Application " -ForegroundColor Blue
Write-Host "============================================" -ForegroundColor Blue
Write-Host ""
}
# --- GET INFO FROM USER AND ADD A NEW ENTRY ---
function Add-Entry {
Write-Host "Enter the information to add a new entry:" -ForegroundColor Yellow
$name = Read-Host "Name"
$phone = Read-Host "Phone Number"
$email = Read-Host "Email"
Add-Content -LiteralPath $AddressBookFile -Value "$name, $phone, $email" -Encoding UTF8
Write-Host "Entry added successfully." -ForegroundColor Green
}
# --- READ AND DISPLAY ADDRESS BOOK ENTRIES ---
function Show-Entries {
Write-Host "Address Book:" -ForegroundColor Blue
if (Test-Path -LiteralPath $AddressBookFile) {
Get-Content -LiteralPath $AddressBookFile | ForEach-Object {
$fields = $_ -split ',\s*'
if ($fields.Count -ge 3) {
Write-Host "Name: $($fields[0]), Phone: $($fields[1]), Email: $($fields[2])"
}
}
} else {
Write-Host "Address book not found." -ForegroundColor Red
}
}
# --- DELETE AN ENTRY ---
function Remove-Entry {
$nameToDelete = Read-Host "Enter the name you want to delete"
if (Test-Path -LiteralPath $AddressBookFile) {
$remainingLines = @()
$found = $false
Get-Content -LiteralPath $AddressBookFile | ForEach-Object {
$fields = $_ -split ',\s*'
if ($fields.Count -ge 1 -and $fields[0] -eq $nameToDelete) {
$found = $true
} else {
$remainingLines += $_
}
}
Set-Content -LiteralPath $AddressBookFile -Value $remainingLines -Encoding UTF8
if ($found) {
Write-Host "Entry deleted successfully." -ForegroundColor Green
} else {
Write-Host "No entry found with that name." -ForegroundColor Yellow
}
} else {
Write-Host "Address book not found." -ForegroundColor Red
}
}
# --- MAIN MENU ---
while ($true) {
Show-Header
Write-Host "Address Book Application" -ForegroundColor Blue
Write-Host "1. Add New Entry"
Write-Host "2. Show Entries"
Write-Host "3. Delete Entry"
Write-Host "4. Exit"
$choice = Read-Host "Make your choice (1/2/3/4)"
Write-Host ""
switch ($choice) {
"1" { Add-Entry }
"2" { Show-Entries }
"3" { Remove-Entry }
"4" {
Write-Host "Exiting..." -ForegroundColor Yellow
Read-Host "`nPress ENTER to exit."
exit 0
}
default { Write-Host "Invalid choice, please try again." -ForegroundColor Red }
}
Write-Host ""
Read-Host "Press Enter to continue"
}Konu anlatımına gerek yok, aşağıdaki ekran görüntülerine bakın yeter...
Kayıt Ekleme :





Betiği hangi konum'da çalıştırırsanız o konumda .DAT dosyası oluşturulur.

