I have two questions: why the following function in the script is not recognized when the script runs:
Script:
$pathN = Select-Folder Write-Host "Path " $pathN function Select-Folder($message='Select a folder', $path = 0) { $object = New-Object -comObject Shell.Application $folder = $object.BrowseForFolder(0, $message, 0, $path) if ($folder -ne $null) { $folder.self.Path } }
I get an error message:
The term 'Select-Folder' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try aga
in.
But if I download and run it in Windows PowerShell ISE, it will give me an error for the first time, and then it will act as if it "registered" this function and works after that.
And in case this is a procedural problem, I tried to list the function at the top, not good luck.
Note I tried simple functions such as:
Write-host "Say " Hello function Hello { Write-host "hello" }
With the same exact results / error, he complains that Hello is not a function ....
In addition, still not everyone works only with running a script in powershell (only in ISE after the first initial attempt).
source share