As @KenWhite said, you don't clearly say what the problem is, but, I took you sample and fixed all the issues I could find. Maybe, this will help you.
Example using PowerShell 5 Compress-Archive function
Function ZipOnebyOne{
param(
[Parameter(Mandatory=$true)]
[string]
$filepath
)
$extension = Get-ChildItem $filePath -File -Recurse
foreach ($file in $extension) {
$name = $file.name
$directory = $file.DirectoryName
$fileExtension = $file.Extension
$zipfile = $name.Replace($fileExtension, '.zip')
Compress-Archive -Path (Join-Path $directory $name) -DestinationPath (Join-path $directory $zipfile) -Update
}
}
Example using 7-Zip
Function ZipOnebyOne{
param(
[Parameter(Mandatory=$true)]
[string]
$filepath
)
$7z = 'C:\Program Files\7-Zip\7z.exe'
$extension = Get-ChildItem $filePath -File -Recurse
foreach ($file in $extension) {
$name = $file.name
$directory = $file.DirectoryName
$fileExtension = $file.Extension
$zipfile = $name.Replace($fileExtension, '.7z')
$null = & $7z -t7z a (Join-path $directory $zipfile) (Join-Path $directory $name)
}
}