While assisting another IT Professional with a PowerShell issue, we came across a syntax difference between PowerShell V2 and V3 with regards to using a hash with the Get-ADUser cmdlet. I was utilizing PowerShell V3 while the other individual was on V2. Here is the code that worked on V3: $ADHash = @{Filter = '(Surname -eq $Last) -and (GivenName -eq $First)' ; SearchBase = $( $OU . DistinguishedName)} Get-ADUser @ADHash In this example, a hash is being created for the Get-ADuser cmdlet. Both a value for the Filter and another for the SearchBase parameters were being created. The problem came down to the filter. In PowerShell V3, a complex filter is allowed. That is, a filter that is using a logical operator such as –as or –or . Here is the same code, but codded for V2. Get-ADUser -filter * -SearchBase " $( $OU . DistinguishedName) " | Where-Object {( $_ . GivenName -eq $First ) -and ( $_ . Surname -eq $Last )
Welcome to the blogsite of MCTExpert. I am a Microsoft Certified Trainer. Here you will find the real questions that are asked to me by my students.