Get-ADUser -Filter 'name -like question

Hello,

I created some users in Active Directory called Person 1, Person 2, Person 3, and Person 4. If I do

(Get-ADUser -Filter ‘name -like “Person 1”’).Name
, it will find “Person 1”, but when I do
(Get-ADUser -Filter ‘name -like "’$GetMFNames’"').Name
, it gives an error message.

What I’m trying to do is, automate the process of adding employees pictures to Outlook using the ActiveDirectory thumbnailphoto attribute.

# test people are in Test-OU-Darcy
#$MFPhotos = [System.IO.File]::ReadAllBytes($IntranetPhotoMFFolder)
#$PioneerPhotos = [System.IO.File]::ReadAllBytes($IntranetPhotoPioneerFolder)
#$FindMFADUsers = (Get-ADUser -Filter 'name -like "Person 1"').Name
#Set-ADUser ttantony -Replace @{thumbnailPhoto=$MFPhotos}

$IntranetPhotoMFFolder = '\\hqfs1\Shares\HQShared\Intranet\Intranet Employee Photo'
$IntranetPhotoPioneerFolder = '\\hqfs1\Shares\HQShared\Intranet\Intranet Pioneer Photos'
$GetMFNames = Get-ChildItem $IntranetPhotoMFFolder -Exclude Completed | % {$_.BaseName}
$GetPioneerNames = Get-ChildItem $IntranetPhotoPioneerFolder -Exclude Completed | % {$_.BaseName}

ForEach($Employees in $GetMFNames)
{
    #(Get-ADUser -Filter 'name -like "Person 1"').Name
    (Get-ADUser -Filter 'name -like "'$GetMFNames'"').Name
}

Thank you,
Tony

This is the error message:

PS C:\Windows\system32> \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1
Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 1 Person 2 Person 3 Person 4"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:15 char:6

  • (Get-ADUser -Filter 'name -like "'$GetMFNames'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 1 Person 2 Person 3 Person 4"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:15 char:6

  • (Get-ADUser -Filter 'name -like "'$GetMFNames'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 1 Person 2 Person 3 Person 4"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:15 char:6

  • (Get-ADUser -Filter 'name -like "'$GetMFNames'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 1 Person 2 Person 3 Person 4"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:15 char:6

  • (Get-ADUser -Filter 'name -like "'$GetMFNames'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Your command is passing all of the users in the variable $GetMFNames rather the the one that you are currently processing
Try this

ForEach($Employees in $GetMFNames)
{
    #(Get-ADUser -Filter 'name -like "Person 1"').Name
    (Get-ADUser -Filter 'name -like "'$Employees'"').Name
}
# test people are in Test-OU-Darcy
#$MFPhotos = [System.IO.File]::ReadAllBytes($IntranetPhotoMFFolder)
#$PioneerPhotos = [System.IO.File]::ReadAllBytes($IntranetPhotoPioneerFolder)
#$FindMFADUsers = (Get-ADUser -Filter 'name -like "Person 1"').Name
#Set-ADUser ttantony -Replace @{thumbnailPhoto=$MFPhotos}

$IntranetPhotoMFFolder = '\\hqfs1\Shares\HQShared\Intranet\Intranet Employee Photo'
$IntranetPhotoPioneerFolder = '\\hqfs1\Shares\HQShared\Intranet\Intranet Pioneer Photos'
$GetMFNames = Get-ChildItem $IntranetPhotoMFFolder -Exclude Completed | % {$_.BaseName}
$GetPioneerNames = Get-ChildItem $IntranetPhotoPioneerFolder -Exclude Completed | % {$_.BaseName}

ForEach($Employees in $GetMFNames)
{
    #(Get-ADUser -Filter 'name -like "Person 1"').Name
    #(Get-ADUser -Filter 'name -like "'$GetMFNames'"').Name
    (Get-ADUser -Filter 'name -like "'$Employees'"').Name
}

Thank you, I did that, and now it says this. This is a different error message than earlier.

Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 1"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:16 char:6

  • (Get-ADUser -Filter 'name -like "'$Employees'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 2"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:16 char:6

  • (Get-ADUser -Filter 'name -like "'$Employees'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 3"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:16 char:6

  • (Get-ADUser -Filter 'name -like "'$Employees'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Get-ADUser : A positional parameter cannot be found that accepts argument ‘Person 4"’.
At \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1:16 char:6

  • (Get-ADUser -Filter 'name -like "'$Employees'"').Name
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ADUser], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

try

ForEach($Employees in $GetMFNames)
{
    #(Get-ADUser -Filter 'name -like "Person 1"').Name
    #(Get-ADUser -Filter 'name -like "'$GetMFNames'"').Name
    (Get-ADUser -Filter 'name -like $Employees').Name
}

Thanks, that was it

(Get-ADUser -Filter 'name -like $Employees').Name

PS C:\Windows\system32> \hqfs1\users\tantony\PowerShell\AddPhoto\AddPhoto.ps1
Person 1
Person 2
Person 3
Person 4

PS C:\Windows\system32>