Forum Discussion

baijiaying's avatar
baijiaying
Copper Contributor
Feb 22, 2019

Get different results in new powershell process and active process

I execute the following code in a new powershell process, get the results

"chrome IE"

Continue run the same code in the active powershell process get the results with new line

"chrome

IE"

I think this may be related with the type issues. But I still don't know why the same code results is different in new powershell process and active powershell process.

 

Param(
[string]$Browsers = "Chrome,IE"
)

$browsers = $Browsers.split(",")

foreach ($browser in $browsers) {
$browser
}

  • The Param() statement should only be used within a function definition, not directly. Other than that, check if something isn't modifying the $Browsers variable, and make sure you are always using it in the correct scope.

Resources