Get-ADGroup wild card confusion

Welcome Forums General PowerShell Q&A Get-ADGroup wild card confusion

This topic contains 6 replies, has 3 voices, and was last updated by

 
Participant
2 months, 1 week ago.

  • Author
    Posts
  • #144774

    Participant
    Topics: 17
    Replies: 49
    Points: 96
    Rank: Member

    Good morning experts!
    Running the following script:

    $GNames = Import-CSV -Path D:\Powershell_temp\danea_info.csv| ForEach-Object { 
        Get-ADGroup -Filter "Name -like '*$($_.name)*'" } | Select-Object Name
    

    is not working the way I thought it was. The only way I can produce output in $GNames is to place * around $($_.name) In doing that I'm
    getting additional groups that are not in the input csv file. So the obvious solution to my feeble mind would be to remove the second wildcard, nope no worky removing the second wildcard the $GNames is empty, removing both wildcards $GNames is empty. Obviously not doing something right, please advise and correct my ignorance.

    Thank you

    Norm

  • #144782
    js

    Participant
    Topics: 21
    Replies: 592
    Points: 1,151
    Helping Hand
    Rank: Community Hero

    Works perfectly for me. Without the * wildcards, you might as well use -eq instead of -like. What does the csv look like? Are they exact matches for group names?

  • #144798

    Participant
    Topics: 17
    Replies: 49
    Points: 96
    Rank: Member

    Good afternoon,
    It's still not working for me the following was in the input file BUT not in $GNames dgMSEPP-ServerSQL. They are exact matches of Group Names. Here is the entry in the .csv file dgMSEPP-ServerSQL There is a since of urgency on this, need to get this script which I thought was working by 4pm PST today.

    Thank you for your help
    Norm

  • #144800
    js

    Participant
    Topics: 21
    Replies: 592
    Points: 1,151
    Helping Hand
    Rank: Community Hero

    I don't see the input file?

  • #144809

    Participant
    Topics: 17
    Replies: 49
    Points: 96
    Rank: Member

    Good afternoon,
    Looks like I've been sabotaged. It appears another admin may have deleted some of the group entries in their spreadsheet sent to me. So the following does indeed work

    $GNames = Import-CSV -Path D:\Powershell_temp\danea_info.csv| ForEach-Object { 
        Get-ADGroup -Filter "Name -eq '$($_.name)'" -Properties Name } | Select-Object Name 
    

    Apologize for the additional posts, good to know haven't lost my mind

    Thanks again

    Norm

  • #144810
    js

    Participant
    Topics: 21
    Replies: 592
    Points: 1,151
    Helping Hand
    Rank: Community Hero

    Glad it's resolved.

  • #144812

    Participant
    Topics: 2
    Replies: 937
    Points: 1,628
    Helping Hand
    Rank: Community Hero

    Take the file out of the mix.

    # So, if you did this generally...
    
    $GroupArray = 'AD','ADS'
    
    $GroupArray | %{(Get-ADGroup -Filter "Name -like '$PSItem*'").Name}
    
    $GroupArray | %{(Get-ADGroup -Filter "Name -like '*$PSItem*'").Name}
    
    # ... that you don't get back what is expected?
    

You must be logged in to reply to this topic.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort