0

I am running into an issue where about 10% of computers on my network are throwing a very strange errors when processing. The error I get is "Where-Object : A Parameter cannot be found that matches paramter name 'Property'" the code I'm using is as follows.

#Create ADSI Search object to query Active Directory for usernames
#Start-Transcript -Path "$env:userprofile\Desktop\log.txt"
$strFilter = "objectCategory=user"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=SD25;DC=DC;DC=DC")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 100000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"

#Populate ADSI with the extra fields of samaccountname which is the username, and memberof which gives you roughly which groups they are a memberof
$colProplist = "samaccountname", "memberof"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

#Run the Search
$colResults = $objSearcher.FindAll()
#$colResults
$resultsarray = @() 

#The way ADSI returns results, it populates all an array of every username listed within the scope, I then use this foreach recursive loop to find the name I need
foreach ($objResult in $colResults)
    {
        #Here I am taking each of the users, and finding the one which has the samaccountname of the user that is currently logged in 
    $objItem = $objResult.Properties | Where-Object -Property memberof -like ALL
    #$groups = $objItem.memberof
    #This is for diagnostics, if you output a logfile it will tell you the name and groups it is a member of
    $objitem



}

#This is the beginnings of searching for a computer container in active    directory.
$compFilter = "objectCategory=computer"
$compDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=OU;DC=DC;DC=DC")
$compSearcher = New-Object System.DirectoryServices.DirectorySearcher
$compSearcher.SearchRoot = $objDomain
$compSearcher.PageSize = 100000
$compSearcher.Filter = $strFilter
$compSearcher.SearchScope = "Subtree"

$compProplist = "name" 
foreach ($i in $compPropList){$compSearcher.PropertiesToLoad.Add($i)}

$compResults = $compSearcher.FindAll()

foreach ($compR in $compResults)
    {

    }
#Stop-Transcript
  • Wild guess: on the hosts throwing the error you have a custom function `Where-Object` that supersedes the builtin cmdlet? What's the output of `Get-Help Where-Object` on these hosts? – Ansgar Wiechers Jul 29 '15 at 19:38
  • It's the normal output, that it is a filter. and the thing is with these computers, nobody has ever even opened powershell, or powershell ISE on them. – user3312045 Jul 29 '15 at 20:45
  • For info, the maximum PageSize for AD is 1000. There's no point in setting it any higher. – user2871239 Jul 30 '15 at 08:29
  • I'm not familiar with GPO scripts. Is this script running on every box? This line suggests you're trying to find the samAccountName of the logged on user: "Here I am taking each of the users, and finding the one which has the samaccountname of the user that is currently logged in". If you are, there are better ways. – user2871239 Jul 30 '15 at 08:30
  • This script is running on every box. Yes, there are better ways, if I were to install rsat and have the AD drive and cmdlets available to every person in my network..., but since at least 4000 of my users are children, I am a little loathe to do that. As for the page size, my finger probably just bumped to zero too many times while I was coding it – user3312045 Aug 03 '15 at 14:09

1 Answers1

0

IIRC -Property was introduced to Where-Object with PowerShell 3.0. Could you script be running on PowerShell 2.0?

Responding to comment

You need to create a filter script in the form of a scriptblock (i.e. PowerShell code in a set of braces) instead of using the comparison operator parameters they added for 3.0.

Try using

Where-Object { $_.memberof -like "ALL" }

or something like that. $_ refers to the current object in the pipeline. I couldn't find the docs for version 2.0 but I found Using the Where-Object Cmdlet for version 1.0 which was relevant for 2.0 AFAIK and should help you.

user2871239
  • 1,499
  • 2
  • 11
  • 27
  • you are right, they are running Powershell v 2.0, I really need that parameter though, is there any way to simulate it in 2.0? – user3312045 Aug 03 '15 at 14:12