Dealing with Spaces from a Query

Welcome Forums General PowerShell Q&A Dealing with Spaces from a Query

This topic contains 2 replies, has 2 voices, and was last updated by  bvi1998 . 3 years, 5 months ago.

  • Author
  • #33939

    Topics: 30
    Replies: 61
    Points: 58
    Rank: Member

    I am querying a user for an AD group name. I then want to confirm the group is in AD. However, the group name has spaces. I have tried many things to deal with this, none of which is successful. This is an excerpt of the script I am using:

    $Trustee = 'WinNT://',"$env:userdomain",'/',"$trustee" -join "
    $ADResolve = ([adsisearcher]"(samaccountname=$Trustee)").findone().properties['samaccountname']

    Can someone help me?

  • #33940

    Topics: 13
    Replies: 4872
    Points: 1,813
    Helping HandTeam Member
    Rank: Community Hero

    With that syntax, you're usually querying for the samAccountName, which doesn't usually have spaces... that's different from the display name.

    But, out of curiosity, why wouldn't you use either Get-ADGroup, or the LDAP:// provider, versus WinNT://? Going through the old-old-old WinNT interface seems like you'd always just run across challenges.

The topic ‘Dealing with Spaces from a Query’ is closed to new replies.