Get-ADUser -Filter 'name -like question

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Tony Antony Tony Antony 8 months ago.

  • Author
    Posts
  • #54660
    Profile photo of Tony Antony
    Tony Antony
    Participant

    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 topic was modified 8 months ago by Profile photo of Tony Antony Tony Antony.
  • #54663
    Profile photo of Tony Antony
    Tony Antony
    Participant

    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: (:) [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: (:) [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: (:) [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: (:) [Get-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

  • #54664
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    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
    }
    • #54665
      Profile photo of Tony Antony
      Tony Antony
      Participant
      # 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: (:) [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: (:) [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: (:) [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: (:) [Get-ADUser], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

  • #54667
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    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
    }
  • #54668
    Profile photo of Tony Antony
    Tony Antony
    Participant

    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>

You must be logged in to reply to this topic.