Powershell Function Name as "main" Strange Effect
powershell
Solution
Because at the time main is called the first time, there is no function main, so PowerShell is looking for another thing called main to execute. The second time it knows about the main function and that gets precedence above main.cpl.
The solution is simple. Declare the main function before you call it the first time.
function main
{
cls
Write-Host "hi"
}
main
I do not have an answer why PowerShell decides to execute main.cpl when you type main, but the same goes for main.exe if you have it in $env:path.
Problem
Check out this code: ``` main function main { cls Write-Host "hi" } ``` If you run it for the first time, the windows Mouse Properties window will load. Run it again and it will display "hi". Why is this? I understand that main.cpl is the Mouse Properties window. But why is it that it opens only the first time, then the 2nd time Powershell realises that you actually want to call the "main" function. Shouldn't Powershell detect this and ask you to write main.cpl instead if you want the mouse properties window?