Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Parameter Binding Issue

$
0
0

I have an advanced function that that looks something like this:

function Audit-System
{
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [Alias("Name")]
        [string[]]$ComputerName

    )

    Process
    {
        foreach($computer in $ComputerName)
        {
            
            ## Do stuff for every computer
            Write-Verbose $computer


            
        }
    }
}

The followimg work ok:

"computer1","computer2" | Audit-System

Audit-System "computer1","computer2" 

Audit-System "computer1"

The following doesn't work:

Get-ADComputer -Filter *  SearchBase "CN=Computers,DC=contoso,DC=com" | Audit-System -Verbose
I would have thought that because the [Microsoft.ActiveDirectory.Management.ADComputer] has a 'Name' property parameter binding would have matched it up with my $ComputerName parameter. Why doesn't this work?



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>