Open utterances-bot opened 3 years ago
I'm able to do tab completion for the parameter and the parameter values while running the command from the script pane.
function Hello-World
{param( [ValidateSet('Green','Red','Blue')] $Color)
Write-Host "Hello world!" -Foreground $Color
}
However, tab completion doesn't work when the file is in the Scripts folder like other scripts installed using Install-Script
.
$DestPath = [Environment]::GetFolderPath('MyDocuments')+"\PowerShell\Scripts"
(New-Object System.Net.WebClient).DownloadFile("https://github.com/Ayanmullick/test/raw/master/Hello-World.ps1","$DestPath\Hello-World.ps1")
Invoke-Expression "$DestPath\Hello-World.ps1"
I'm able to do tab completion for the parameter and the parameter values while running the command from the script pane.
function Hello-World {param( [ValidateSet('Green','Red','Blue')] $Color) Write-Host "Hello world!" -Foreground $Color }
However, tab completion doesn't work when the file is in the Scripts folder like other scripts installed using
Install-Script
.$DestPath = [Environment]::GetFolderPath('MyDocuments')+"\PowerShell\Scripts" (New-Object System.Net.WebClient).DownloadFile("https://github.com/Ayanmullick/test/raw/master/Hello-World.ps1","$DestPath\Hello-World.ps1") Invoke-Expression "$DestPath\Hello-World.ps1"
Removing the function wrapper in the file being downloaded and adding the default script folder path to $env:PATH
resolved the issue.
If (($env:PATH -split ';') -notcontains $DestPath) {$env:Path += ";$DestPath"}
This was great, thank you on helping me get dynamic tab completion. One part that through me off was that I didn't realize that setting the dynamic param's name is important and must match the name of the variable in the begin.
$ParameterName = 'Service'
I thought it was just setting the initial value, but if you don't properly set this, the the dynamic portion will fail.
Adding tab-completion to your PowerShell Functions
FoxDeploy.com, Stephen Owen's technical blog about PowerShell, Systems Administration, GUI Design and Programming. .
https://www.foxdeploy.com/blog/adding-tab-completion-to-your-powershell-functions.html