更新时间:2023-02-10 20:31:42
The variable $input is a reservd powershell variable (take a look here) and you should not use it in this context.
As in the comments mentiond I would also put an else in your loop and save the input to an array.
[System.Int32[]]$UserInputs = @() #INT Array
do {
[System.Int32]$UserInput = Read-Host -Prompt 'Enter variety of numbers and press 0 to add them together'
if ($UserInput -eq 0)
{
Out-Host -InputObject ('Sum of numbers entered ' + ($UserInputs | Measure-Object -Sum).Sum) #Return the sum
}
else
{
$UserInputs += $UserInput #Add user input to array
}
}
while ($UserInput -ne 0)