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 . 2 years, 11 months ago.

  • Author
    Posts
  • #33939

    Participant
    Points: 31
    Rank: Member

    Hi,
    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?
    Thanks!

  • #33940

    Keymaster
    Points: 1,704
    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.