Advanced Function param

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Advanced Function param

Post by sekou2331 »

Hi,

I want to add a little bit of code as a param. Wanted to know if the below\attached is possible? If is am i approaching this correctly
Attachments
2017-02-15 10_05_30-SAPIEN PowerShell Studio 2017.png
2017-02-15 10_05_30-SAPIEN PowerShell Studio 2017.png (50.84 KiB) Viewed 1669 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Advanced Function param

Post by jvierra »

Please do not post images of code. Post the code using the code posting tool so it can be easily read and copied.
The line highlighted will default to the paths to all MSI files. Add () around the code.
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Advanced Function param

Post by sekou2331 »

Thanks, added it correctly this time. By the way is this the best approach?

  1. function Get-MSIProdCodrRemo () {
  2.     [CmdletBinding()]
  3.     param (
  4.         [Parameter(Mandatory = $true,
  5.                    ValueFromPipeline = $true,
  6.                    ValueFromPipelineByPropertyName = $true)]
  7.         [string[]]$computername,
  8.         [parameter(Mandatory = $true)]
  9.         [string]$msiAppPath,
  10.         [parameter(Mandatory = $true)]
  11.         [string[]] $PathToMsiInstaller = gci "\\$computername\C$\Windows\Installer\*.msi"
  12.             )
  13.     BEGIN
  14.     {
  15.         BeginBlock
  16.     }
  17.     PROCESS
  18.     {
  19.          ProcessBlock
  20.     }
  21.     END
  22.     {
  23.         EndBlock
  24.     }
  25. }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Advanced Function param

Post by jvierra »

That depends on what you are trying to do.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked