Passing values through pipeline to function but function keeps asking for parameter

I’m messing this up somewhere simple and I’m just not seeing it today. When I pass values through the pipeline, the function keeps asking me for the $ComputerName parameter. What am I doing wrong?

function Do-Stuff { [CmdletBinding()] param( [Parameter( Position = 0, Mandatory = $true, ValueFromPipeline = $true) ] $ComputerName, [Parameter(Mandatory = $true)] [int32]$vlanid, [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $DefCreds = [System.Management.Automation.PSCredential]::Empty ) process { foreach ($server in $ComputerName) { Write-host "Doing stuff to $server" } } } 

Example:

PS: C:WindowsSystem32> "10.10.0.1","10.10.0.2" | Do-Stuff -DefCreds (Get-Credential) -vlanid 20 Supply values for the following parameters: ComputerName: 

Also tried:

PS: C:WindowsSystem32> "10.10.0.1","10.10.0.2" | % { Do-Stuff -DefCreds (Get-Credential) -vlanid 20 } Supply values for the following parameters: ComputerName: 

submitted by /u/Ghlave
[link] [comments]

Leave a Reply