Skip to main content

Posts

Showing posts from June, 2013

Active Directory Module Filter/Hash compatibility issues Between V2 and V3

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 )

Using Text Based Logs with Windows PowerShell (8 of 8)

Day 8: The Final Product   Yesterday we created our custom empty object.   Today we send the final set of data to the PowerShell pipeline by completing the final two steps:   4.        Read the log records into the object. 5.        Send to the pipeline. For this final phase of this project, we will be adding the function New-LogObject to our cmdlet.   In this function, we will place the properties from the log file record into a PowerShell object and send these objects into the pipeline.        Function New-LogObject     {     Param ( $PropList , $RecordIndex , $EmptyObject , $Log )     # Creates the final object for each log record and returns the     # Custom.LogObject back to the calling statement.           # Create an instance of Custome.Logobject         $Obj = $EmptyObject           # Cycle through each record and populate the object.         ForEach ( $R in $RecordIndex )         {             # Write the slot information.