Why don’t you run it in one Invoke-Command? … like this?
$fileserver = Read-Host "Merci de renseigner le File_Server "
Invoke-Command -ComputerName $fileserver -ScriptBlock {
$name = Read-Host "Merci de renseigner le nom de l’utilisateur "
Get-SmbOpenFile | Where-Object -Property ClientUserName -Contains $name | Format-Table
$sessionid = Read-Host "Merci de renseigner la session ID a fermer "
Close-SmbOpenFile -FileId $sessionid
}
Ah … I see. There’s an easy trick how to trick the output optimization of Powershell. Simply add a format cmdlet like Format-Table. I updated my code suggestion in my first answer. Try it now.