I’m trying to write a PS function that takes a -Computername parameter. Here is the code I’m using:
function Get-Foo {
param(
[Parameter(Mandatory=$False,Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[string[]]$Computername = $env:COMPUTERNAME
)
However, when I run the function as Get-Foo -Computername BAZ it never passes the named parameter BAZ, but instead always uses the value of $env:COMPUTERNAME. I’m generally new to PowerShell, and definitely to writing functions, so hopefully someone can quickly see where I’m going wrong here. I cut and modified the param line from another script that does work, so I don’t know why it doesn’t work here… Thanks.
How are you calling it? It worked for me in all the various types of way it could be set:
All of which output “hi”.