mbegan / Okta-PSModule

Okta API Powershell Wrapper Module
Other
102 stars 31 forks source link

oktaListUsers to query users matching specific profile attribute values #26

Open ghost opened 5 years ago

ghost commented 5 years ago

Hi, I want to query all users with the profile.title value matching "some title". I tried by using "oktaListUsers" like below but looks like it paginates but doesn't fetch anything:

oktaListUsers -oOrg prod1 -limit 1000 | Where {$_.profile.title -like "VP"}

I may not be doing it right. Can you give me some pointers ? I tried using "get-help oktaListUsers" which isn't much of a help either.

Thanks, Roy

CJChristensen commented 5 years ago

We use the following to pull info out of the oktaListActiveUsers command.

(oktaListActiveUsers -oOrg prod1).profile | select firstname,lastname,email,employeenumber | export-csv c:\temp\oktausers1.csv

I am sure you could add a filter to where I have the select statement.

Out of curiosity, if this module still working for you? I am getting the below error message when running oktaGetUserbyID or really any command inside of this module/wrapper

WARNING: Unable to find type [Microsoft.PowerShell.Commands.HttpResponseException]. WARNING: Encountered error, returning limited or empty set

If use the connect-okta -token -fulldomain from the okta.core.automation module I can then run commandlets in this okta module. Really strange behavior and its doing the same thing on everyone's computers over here.

alexc307 commented 5 years ago

Same error here @CJChristensen . Did you find a fix for it by any chance?

ghost commented 5 years ago

@CJChristensen and @alexc307

I started getting "Unauthorized (401)" with this module. So I switched to the official PS module (okta.core.automation).

rlackner commented 5 years ago

Has anyone found a fix for that issue with not being able to load that HttpResponseException type? I'm pretty good with PowerShell, but I'm not familiar with loading types....

rlackner commented 5 years ago

So, Microsoft.PowerShell.Commands.Utility.dll apparently contains the HttpResponseException typ, so, when I try this:

add-type -Path "C:\Program Files\powershell\6\Microsoft.PowerShell.Commands.Utility.dll"

I get this:

add-type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. At C:\ProgramData\Scripts\sync_ADgroups_to_Oktagroups_MO.ps1:6 char:1

So, I'm probably not loading the correct type? I have upgraded to PS 6.1 on Windows Server 2012 R2.

rlackner commented 5 years ago

So, I updated to powershell "core" version 6.1.0, loaded Visual Studio Code, installed the Powershell and vscode-icons extensions, reloaded VS Code, then needed to update the Settings (gear icon in lower left) / Workspace Settings / PowerShell Configuration / Power Shell Exe Path to C:\Program Files\PowerShell\6\pwsh.exe and reload Powershell. Updated version shows up now:

PS C:\ProgramData\Scripts> $psversiontable

Name Value


PSVersion 6.1.0 PSEdition Core GitCommitId 6.1.0 OS Microsoft Windows 6.3.9600 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

However, the new PS version no longer references the folder where the Okta module has been, so I'll need to move it to a different path -- but, at least, no longer running into that type issue any longer:

Import-Module : The specified module 'Okta' was not loaded because no valid module file was found in any module directory. At C:\ProgramData\Scripts\sync_ADgroups_to_Oktagroups_MO.ps1:16 char:5

rlackner commented 5 years ago

I copied the Okta module to c:\program files\powershell\6\modules\ -- worked.