fix for #35, get-user by email or username

This commit is contained in:
Petri Asikainen 2021-05-16 13:13:23 +03:00
parent 4ed189b45d
commit 981e90e103

View file

@ -33,7 +33,7 @@ Get-User -url "https://assets.example.com" -token "token..." | Where-Object {$_.
function Get-User() { function Get-User() {
Param( Param(
[string]$search, [string]$search,
[string]$id, [string]$id,
[int]$company_id, [int]$company_id,
@ -44,6 +44,10 @@ function Get-User() {
[int]$department_id, [int]$department_id,
[string]$username,
[string]$email,
[ValidateSet("asc", "desc")] [ValidateSet("asc", "desc")]
[string]$order = "desc", [string]$order = "desc",
@ -61,15 +65,15 @@ function Get-User() {
) )
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/users" $apiurl = "$url/api/v1/users"
if ($search -and $id ) { if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} }
if ($id) { if ($id) {
$apiurl= "$url/api/v1/users/$id" $apiurl= "$url/api/v1/users/$id"
} }
$Parameters = @{ $Parameters = @{
Uri = $apiurl Uri = $apiurl
@ -85,8 +89,8 @@ function Get-User() {
while ($true) { while ($true) {
$callargs['offset'] = $offstart $callargs['offset'] = $offstart
$callargs['limit'] = $limit $callargs['limit'] = $limit
$res=Get-User @callargs $res=Get-User @callargs
$res $res
if ($res.count -lt $limit) { if ($res.count -lt $limit) {
break break