Get different results in new powershell process and active process

%3CLINGO-SUB%20id%3D%22lingo-sub-355114%22%20slang%3D%22en-US%22%3EGet%20different%20results%20in%20new%20powershell%20process%20and%20active%20process%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-355114%22%20slang%3D%22en-US%22%3E%3CP%3EI%20execute%20the%20following%20code%20in%20a%20new%20powershell%20process%2C%20get%20the%20results%3C%2FP%3E%3CP%3E%22chrome%20IE%22%3C%2FP%3E%3CP%3EContinue%20run%20the%20same%20code%20in%20the%20active%20powershell%20process%20get%20the%20results%20with%20new%20line%3C%2FP%3E%3CP%3E%22chrome%3C%2FP%3E%3CP%3EIE%22%3C%2FP%3E%3CP%3EI%20think%20this%20may%20be%20related%20with%20the%20type%20issues.%20But%20I%20still%20don't%20know%20why%20the%20same%20code%20results%20is%20different%20in%20new%20powershell%20process%20and%20active%20powershell%20process.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EParam(%3CBR%20%2F%3E%5Bstring%5D%24Browsers%20%3D%20%22Chrome%2CIE%22%3CBR%20%2F%3E)%3C%2FP%3E%3CP%3E%24browsers%20%3D%20%24Browsers.split(%22%2C%22)%3C%2FP%3E%3CP%3Eforeach%20(%24browser%20in%20%24browsers)%20%7B%3CBR%20%2F%3E%24browser%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20308px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F84009iEFA712FDEC08F1A8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Capture.PNG%22%20title%3D%22Capture.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-355114%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-355183%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20different%20results%20in%20new%20powershell%20process%20and%20active%20process%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-355183%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20Param()%20statement%20should%20only%20be%20used%20within%20a%20function%20definition%2C%20not%20directly.%20Other%20than%20that%2C%20check%20if%20something%20isn't%20modifying%20the%20%24Browsers%20variable%2C%20and%20make%20sure%20you%20are%20always%20using%20it%20in%20the%20correct%20scope.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

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
}

Capture.PNG

1 Reply
Highlighted

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.