0

Playing around with powershell and am getting funky print out of "0" at the end of both a write-host and or return statements. Unsure how to fix that. I am sure its a dumb mistake I am doing... anyone know why this happens?

Code:

function New-Test(){
     param(
         [String] $stringTest,
         [Int] $intTest
     )
     
     Write-Host $stringTest, $intTest

}

# calling function

New-Test("Hello World", 26)

Output is: Hello World 23 0 --> notice the 0 output... why does this happen and how do I get rid of this?

  • 2
    Short answer - remove the brackets and the comma. Powershell only uses brackets to call .net methods, not functions / cmdlets. What you’re *actually* doing is passing an array ```(“Hello World”, 26)``` to ```$stringTest``` which Powershell then casts to a string, and it’s using a default value for ```$intTest``` which is ```0```. This is definitely a duplicate question though, but I’m using my phone so it’s not so easy to find right now… – mclayton Nov 16 '21 at 19:16
  • Thanks @mclayton, i will continue to look into the documentation. Thanks again for your help. I appreciate it. – marcosvaldez81 Nov 16 '21 at 19:21
  • Good summary, @mclayton; I've found several duplicates and have closed the question. – mklement0 Nov 16 '21 at 21:41

0 Answers0