Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-GSUser with first and last name #10

Closed
cooper opened this issue Jan 25, 2018 · 5 comments
Closed

Get-GSUser with first and last name #10

cooper opened this issue Jan 25, 2018 · 5 comments
Assignees
Labels

Comments

@cooper
Copy link

cooper commented Jan 25, 2018

Is it possible to call Get-GSUser to fetch info for a user based on first and last name rather than username?

@scrthq
Copy link
Member

scrthq commented Jan 25, 2018

Hey Cooper,

With the current released version, Get-GSUser is limited to what Google get user API call options are (which necessitate a UserId / primary email). You would need to use Get-GSUserList -Query $query to do what you're looking to do (but it's 100% doable). You'll need to follow Google's User Search syntax for this: https://developers.google.com/admin-sdk/directory/v1/guides/search-users

Here's an example that I just tested with:

Get-GSUserList -Query "name='Nate Ferrell'"

That all being said, v2.0.0 of PSGSuite allows you to leverage Get-GSUser as a one-stop-shop to provide a level of parity with Get-ADUser -Filter $filter if you're familiar with searching for users. Quick example of how this would be done a little closer to expected syntax with the new version:

Get-GSUser -Filter "name -eq 'Nate Ferrell'"

Cheers!

  • Nate

@scrthq scrthq self-assigned this Jan 25, 2018
@cooper
Copy link
Author

cooper commented Jan 25, 2018

Great, thanks for the info.

@cooper cooper closed this as completed Jan 25, 2018
@cooper
Copy link
Author

cooper commented Jan 26, 2018

In your example, for Get-GSUserList, how can I query a user by a variable first and last name that might contain apostrophes/single quotes?

@cooper cooper reopened this Jan 26, 2018
@scrthq
Copy link
Member

scrthq commented Jan 26, 2018

As Google requires string search values to be wrapped in single quotes/apostrophes, you need to escape any apostrophes in your search string with a backslash. You would need to do string replacement in line if you're doing it programmatically to account for this

# Searching for someone with the exact name "John O'Neal"
$name = "John O'Neal"
Get-GSUserList -Query "name='$($name.Replace("'","\'"))'"

If you're just running commands on the fly and not storing the name in a variable:

Get-GSUserList -Query "name='John O\'Neal'"

@cooper
Copy link
Author

cooper commented Jan 29, 2018

Thank you for that. I decided it was faster to download the entire user list at the start of the script and use something like:

$GSAccount = $googleAccounts | Where-Object { $_.name.fullName -eq $stud.Display }

@cooper cooper closed this as completed Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants