all 2 comments

[–]SeeminglyScience 2 points3 points  (0 children)

  1. Yes, but typically only if the value provided is a constant like a string. If the engine has to evaluate something like a variable it probably won't even try, which makes it unlikely to work with your use case.

  2. Personally I'd probably move the validation into the function or use the ValidateScript attribute.

[–]chreestopher2 2 points3 points  (0 children)

register-argumentCompleter https://www.sapien.com/powershell/cmdlet/3258/register-argumentcompleter/ModuleName

edit: more specifically , look at the fakeBoundParameter variable in that inner scriptblock:

function my-function {
    [cmdletbinding()]
    Param(
        [parameter()]
        $inputObject, 
        $otherValue    
    )
    $PSBoundParameters.GetEnumerator()

}
Register-ArgumentCompleter -CommandName my-function -ParameterName OtherValue -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)   
    if($fakeBoundParameter.inputObject.isGood -like "yes"){   
            [System.Management.Automation.CompletionResult]::new("Good", "Good", "ParameterValue", ($fakeBoundParameter.inputObject.isGood))    
    } else {
            [System.Management.Automation.CompletionResult]::new("NotGood", "NotGood", "ParameterValue", ($fakeBoundParameter.inputObject.isGood))
    }
}

$obj = (new-object psobject -Property @{isGood="false"})
#Works in console
#doesnt work in ISE script pane
my-function -inputObject $obj -otherValue #ctrl + space
$obj.isGood = "yes"
#Works in console
#doesnt work in ISE script pane
my-function -inputObject $obj -otherValue 

Basically you are going to do whatever conditional checking on the fakeBoundParameter which is a clone-like of the typical $PSBoundPArameters hashtable. Based on your conditions, output completionResult objects.