I cleaned up your code a bit, but the underlying problem was in the function. You assigned the result of the format operator to a variable which left nothing to be emitted into the pipeline.
function numberFormat($pnum) {
'{0}-{1} {2} {3} {4}' -f $pnum.Substring(0, 2), $pnum.Substring(2, 2), $pnum.Substring(4, 2), $pnum.Substring(6, 2), $pnum.Substring(8)
}
Import-Csv C:\Temp\import.csv -Encoding UTF8 -Delimiter ';' |
ForEach-Object {
$pnum = $_.mobile -replace "[^0-9]", ""
$pnumlength = $pnum.length
if ($pnumlength -eq 9)
{
numberFormat ('0' + $pnum)
}
elseif ($pnumlength -eq '10')
{
numberFormat $pnum
}
}
Notice that there's no need to surround the arguments in a function call with parentheses. In fact, doing so will cause you headaches, just as separating the arguments with commas will. I left the parens in one function call just to emphasize that adding the '0' was considered to be an expression and not three separate arguments ('0', '+', and $pnum)!