Skip to main content
added 242 characters in body
Source Link
mklement0
  • 451.5k
  • 68
  • 726
  • 985

Define your parameter as follows, which limits the values you may pass to it to one of the values specified in the [ValidateSet()] attribute, which here correspond to the relevant parameter names of Get-Version:

      [Parameter(Mandatory=$True)]
      [ValidateSet('SoftwareName', 'ExePath', 'MsiPath')]
      [string] $LoadedSoftwareParameterType, 

Then pass this parameter's value as the parameter name through to Get-Version, and use the -LoadedSoftwarePath parameter's value as its value, via (hashtable-based) splatting:

$htArgs = @{ $LoadedSoftwareParameterType = $LoadedSoftwarePath }

# ...

$verSWLoaded = Get-Version @htArgs

To give a concrete example: The above makes Update-Software, when invoked with
-LoadedSoftwareParameterType ExePath -LoadedSoftwarePath c:\path\to\foo.exe, in effect internally call
Get-Version -ExePath c:\path\to\foo.exe

Define your parameter as follows, which limits the values you may pass to it to one of the values specified in the [ValidateSet()] attribute, which here correspond to the relevant parameter names of Get-Version:

      [Parameter(Mandatory=$True)]
      [ValidateSet('SoftwareName', 'ExePath', 'MsiPath')]
      [string] $LoadedSoftwareParameterType, 

Then pass this parameter's value as the parameter name through to Get-Version, and use the -LoadedSoftwarePath parameter's value as its value, via (hashtable-based) splatting:

$htArgs = @{ $LoadedSoftwareParameterType = $LoadedSoftwarePath }

# ...

$verSWLoaded = Get-Version @htArgs

Define your parameter as follows, which limits the values you may pass to it to one of the values specified in the [ValidateSet()] attribute, which here correspond to the relevant parameter names of Get-Version:

      [Parameter(Mandatory=$True)]
      [ValidateSet('SoftwareName', 'ExePath', 'MsiPath')]
      [string] $LoadedSoftwareParameterType, 

Then pass this parameter's value as the parameter name through to Get-Version, and use the -LoadedSoftwarePath parameter's value as its value, via (hashtable-based) splatting:

$htArgs = @{ $LoadedSoftwareParameterType = $LoadedSoftwarePath }

# ...

$verSWLoaded = Get-Version @htArgs

To give a concrete example: The above makes Update-Software, when invoked with
-LoadedSoftwareParameterType ExePath -LoadedSoftwarePath c:\path\to\foo.exe, in effect internally call
Get-Version -ExePath c:\path\to\foo.exe

added 387 characters in body
Source Link
mklement0
  • 451.5k
  • 68
  • 726
  • 985

Define your parameter as follows, which limits the values you may pass to it to one of the values specified in the [ValidateSet()] attribute, which here correspond to the relevant parameter names of Get-Version:

      [Parameter(Mandatory=$True)]
      [ValidateSet('SoftwareName', 'ExePath', 'MsiPath')]
      [string] $LoadedSoftwareParameterType, 

Then pass it tothis parameter's value as the parameter name through to Get-Version, and use the -LoadedSoftwarePath parameter's value as followsits value, usingvia (hashtable-based) splatting:

$htArgs = @{ $LoadedSoftwareParameterType = $LoadedSoftwarePath }

# ...

$verSWLoaded = Get-Version @htArgs

Define your parameter as follows:

      [Parameter(Mandatory=$True)]
      [ValidateSet('SoftwareName', 'ExePath', 'MsiPath')]
      [string] $LoadedSoftwareParameterType, 

Then pass it to Get-Version as follows, using (hashtable-based) splatting:

$htArgs = @{ $LoadedSoftwareParameterType = $LoadedSoftwarePath }

# ...

$verSWLoaded = Get-Version @htArgs

Define your parameter as follows, which limits the values you may pass to it to one of the values specified in the [ValidateSet()] attribute, which here correspond to the relevant parameter names of Get-Version:

      [Parameter(Mandatory=$True)]
      [ValidateSet('SoftwareName', 'ExePath', 'MsiPath')]
      [string] $LoadedSoftwareParameterType, 

Then pass this parameter's value as the parameter name through to Get-Version, and use the -LoadedSoftwarePath parameter's value as its value, via (hashtable-based) splatting:

$htArgs = @{ $LoadedSoftwareParameterType = $LoadedSoftwarePath }

# ...

$verSWLoaded = Get-Version @htArgs
Source Link
mklement0
  • 451.5k
  • 68
  • 726
  • 985

Define your parameter as follows:

      [Parameter(Mandatory=$True)]
      [ValidateSet('SoftwareName', 'ExePath', 'MsiPath')]
      [string] $LoadedSoftwareParameterType, 

Then pass it to Get-Version as follows, using (hashtable-based) splatting:

$htArgs = @{ $LoadedSoftwareParameterType = $LoadedSoftwarePath }

# ...

$verSWLoaded = Get-Version @htArgs