locked
Parameters defined inside advanced function does not work with tab completion RRS feed

  • Question

  • I was completing an online training from a website on PowerShell. Instruction completed an advanced function and used parameters. Instruction could use these parameters using tab completion features but I can not. 

    When I copy param code outside function block, I can use tab completion. Works fine with other code examples so should not be a PowerShell console issue. 

    Is there anything wrong with this example code:

            

    function Get-DJOSInfo {
        [cmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')]
        param (
            [Parameter(Mandatory=$True,
                       ValueFromPipeline=$True,
                       ValueFromPipelineByPropertyName=$True)]
            [Alias('hostname')]
            [ValidateLength(5,20)]
            [ValidateCount(1,10)]
            [string[]]$computerName,

            [switch]$nameLog
        )

    I can paste complete code, if required.


    Monday, May 15, 2017 9:52 AM

Answers

  • Works fine for me:

    function Get-DJOSInfo {
    	[cmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low')]
    	param (
    		[Parameter(
    			Mandatory = $True,
    			ValueFromPipeline = $True,
    			ValueFromPipelineByPropertyName = $True
    		)]
    		[Alias('hostname')]
    		[ValidateLength(5, 20)]
    		[ValidateCount(1, 10)]
    		[string[]]$computerName,
    		[switch]$nameLog
    	)
    }

    If its in a file be sure you are dot-sourcing the file.


    \_(ツ)_/

    • Marked as answer by bilalqm Monday, May 15, 2017 1:05 PM
    Monday, May 15, 2017 12:48 PM

All replies

  • Works fine for me:

    function Get-DJOSInfo {
    	[cmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low')]
    	param (
    		[Parameter(
    			Mandatory = $True,
    			ValueFromPipeline = $True,
    			ValueFromPipelineByPropertyName = $True
    		)]
    		[Alias('hostname')]
    		[ValidateLength(5, 20)]
    		[ValidateCount(1, 10)]
    		[string[]]$computerName,
    		[switch]$nameLog
    	)
    }

    If its in a file be sure you are dot-sourcing the file.


    \_(ツ)_/

    • Marked as answer by bilalqm Monday, May 15, 2017 1:05 PM
    Monday, May 15, 2017 12:48 PM
  • Thanks, dot-sourcing is the answer!
    Monday, May 15, 2017 1:05 PM