Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForEach is compulsory with Array Parameters which takes Pipline input #1

Open
Kriegel opened this issue Apr 9, 2018 · 0 comments
Open

Comments

@Kriegel
Copy link

Kriegel commented Apr 9, 2018

Hi Mike,

Preparing for my first teaching a class how to script.
I cant say enough how thankfull I am that you share your stuff with us.
Please feel hugged.

The ForEach() Loop is not necessary on all Array Parameters but for those (main Parameter) who takes Pipeline Input, i think it is compulsory.

So i think that we MUST mention it in our teaching.

In your presentation file (see link below) you present the following Code on line 266 without the ForEach() Loop.

function Test-MrParameterValidation { 
     
     [CmdletBinding()] 
    param ( 
         [Parameter(Mandatory)] 
         [string[]]$ComputerName 
     ) 

    Write-Output $ComputerName 
 } 
 
Test-MrParameterValidation 

for a naive this Code looks fine to work, but it is not without the loop!

better is to mention it and present this Code during the whole presentation:

function Test-MrParameterValidation { 
     
     [CmdletBinding()] 
    param ( 
         [Parameter(Mandatory)] 
         [string[]]$ComputerName 
     ) 

    ForEach($Computer in $ComputerName) {
      Write-Output $Computer
    }
 } 
 
Test-MrParameterValidation 

https://github.com/mikefrobbins/Presentations/blob/dev/Gulf%20Coast%20Code%20Camp%202017/PowerShell%20Toolmaking%20with%20Advanced%20Functions%20and%20Script%20Modules.ps1

cheers Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant