I’m specifying mandatory input parameters as part of a function I’m writing, but I’m wondering how the native AD cmdlets like that string input.
Function Get-IAAMLincPassException { [CmdletBinding()] [OutputType([System.Object])] Param ( # Name should be a valid computer name. [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false)] [Alias('HostName', 'Identity', 'DNSHostName')] [string[]]$computerName, [Parameter(Mandatory = $true, ValueFromPipeline = $false)] [string[]]$lastName, [Parameter(Mandatory = $true, ValueFromPipeline = $false)] [string[]]$firstName ) Begin { } Process { if ($computerInfo = Get-ADComputer $computerName -Properties * -ErrorAction Stop) { if ($userInfo = Get-ADUser -Filter {Surname -eq $lastName -and GivenName -eq $firstName} ) {
This script excerpt bonks out with
Get-ADComputer : Cannot convert 'System.String[]' to the type 'Microsoft.ActiveDirectory.Management.ADComputer' required by parameter 'Identity'. Specified method is not supported.
I’ll keep googling, but perhaps someone can chime in?
Thanks!