Comments (25)
@srirao28
Import-Users
calls New-OktaUser
which is:
https://github.com/gabrielsroka/OktaAPI.psm1/blob/master/Modules/OktaAPI.psm1#L240-L242
from oktaapi.psm1.
Thank you for the comments !
Could you please elaborate a little more on how to achieve my above two tasks.
from oktaapi.psm1.
As I wrote in the readme file, this module assumes you're familiar with the Okta API.
For example:
https://developer.okta.com/docs/reference/api/users/#create-user-with-password
from oktaapi.psm1.
Great,
I am a begginer to powershell and so finding it difficult to consume all the pointers you are helping me with.
For now, configured a virtual box and trying to figure out by running every cmdlet you created in your module.
Will spend time to obsorb the concepts. Thank you for so much for your time !!
from oktaapi.psm1.
You're welcome.
If you noticed, Import-Users
doesn't actually mention passwords anywhere, but there are other examples in the same file that do. If you combine the pieces together, you can probably do what you need. For example:
function Import-UsersWithPassword() {
<# Sample users.csv file. Make sure you include the header line as the first record.
login,email,firstName,lastName,password,groupId
[email protected],[email protected],Test,A1,password1,00g5gtwaaeOe7smEF0h7
[email protected],[email protected],Test,A2,password2,00g5gtwaaeOe7smEF0h7
#>
$users = Import-Csv users.csv
$importedUsers = @()
foreach ($user in $users) {
$newUser = @{
profile = @{
login = $user.login
email = $user.email
firstName = $user.firstName
lastName = $user.lastName
}
credentials = @{
password = @{
value = $user.password
}
}
groupIds = @($user.groupId)
}
$message = ""
try {
$oktaUser = New-OktaUser $newUser $true
} catch {
try {
$oktaUser = Get-OktaUser $user.login
} catch {
$oktaUser = $null
$message = "Invalid user."
}
}
$importedUsers += [PSCustomObject]@{id = $oktaUser.id; login = $user.login; message = $message}
}
$importedUsers | Export-Csv importedUsers.csv -NoTypeInformation
"$($users.count) users read."
}
from oktaapi.psm1.
wow !!
This is really awesome and nice of you !!
I will save above contents to a file with extension .ps1 and run it for myself on my virtualbox.
Will keep you informed on my outcomes, thank you again so much !!
from oktaapi.psm1.
You're welcome.
May I ask why you're running virtualbox? PowerShell runs on Windows, mac and Linux (see my readme for more info).
from oktaapi.psm1.
Sure !!
I am using my work laptop, it does have PowerShell, but it has a rule that blocks me from executing any scripts. So, had to set up VBox/CentOS, configure PowerShell and trigger the script from there.
from oktaapi.psm1.
I see. It makes sense that it might be locked down.
Did you look at:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.1
from oktaapi.psm1.
Thank you for the reference document !!
I will surely review and see if that works for me.
from oktaapi.psm1.
hi @srirao28
i'm following up. did this work for you? if so, please close this issue (or i'll do it in a few days).
you can always reopen it if necessary.
thanks.
from oktaapi.psm1.
Sorry for the delay. Yes, this did work for me, this is great !
QQ - any inputs on the best approach to create groups in okta via csv file.
When to use below snippet ?
# Create a group.
$profile = @{name = $name; description = $description}
$group = New-OktaGroup @{profile = $profile}
** planning to follow below steps:
- add below function to file and name it as importgroups.ps1
- prepare csv file with required group name & description.
- trigger the ps1 script
# Read groups from CSV and create them in Okta.
function New-Groups() {
<# Sample groups.csv file with 2 fields. Make sure you include the header line as the first record.
name,description
PowerShell Group,Members of this group are awesome.
#>
$groups = Import-Csv groups.csv
$importedGroups = @()
foreach ($group in $groups) {
$profile = @{name = $group.name; description = $group.description}
try {
$oktaGroup = New-OktaGroup @{profile = $profile} # <---- SEE HERE
$message = "New group"
} catch {
Get-Error $_
try {
$oktaGroup = Get-OktaGroups $group.name 'type eq "OKTA_GROUP"'
$message = "Found group"
} catch {
Get-Error $_
$oktaGroup = $null
$message = "Invalid group"
}
}
$importedGroups += [PSCustomObject]@{id = $oktaGroup.id; name = $group.name; message = $message}
}
$importedGroups | Export-Csv importedGroups.csv -notype
"$($groups.count) groups read."
}
Any inputs appreciated !!
from oktaapi.psm1.
the 3-line snippet is just an example of how to use New-OktaGroup
by itself.
the New-Groups
function already calls New-OktaGroup
, in a loop, with other stuff (it's about the 12th line in the function).
here's a shorter, simpler version without error checking that might be easier to understand. see line 10 (SEE HERE
)
function New-GroupsNoErrorChecking() {
<# Sample groups.csv file with 2 fields. Make sure you include the header line as the first record.
name,description
PowerShell Group,Members of this group are awesome.
#>
$groups = Import-Csv groups.csv
$importedGroups = @()
foreach ($group in $groups) {
$profile = @{name = $group.name; description = $group.description}
$oktaGroup = New-OktaGroup @{profile = $profile} # <----- SEE HERE
$importedGroups += [PSCustomObject]@{id = $oktaGroup.id; name = $group.name}
}
$importedGroups | Export-Csv importedGroups.csv -notype
"$($groups.count) groups read."
}
from oktaapi.psm1.
Nice explanation, Thank you for all your time !!
I will run it for myself and see how things works for me and share my further thoughts..
from oktaapi.psm1.
Update:
Unfortunately, your script is not working for me. Looks like I messed up something..
---contents of csv file- groups.csv
name, group description
cog-readonly, read only group - cognos
cog-admins, admin group - cognos
cog-sit, sit environment group - cognos
--- contents of ./New-Groups.ps1
#import the OktaAPI module
Import-Module OktaAPI
#Connect-Okta "<API Token>" "https://tenant.okta.com"
#function New-Groups() {
function New-Groups($csvPath){
# Sample groups.csv file with 2 fields. Make sure you include the header line as the first record.
# name,description
# PowerShell Group,Members of this group are awesome.
#
# $groups = Import-Csv groups.csv
$groups = Import-Csv $csvPath
$importedGroups = @()
foreach ($group in $groups) {
$profile = @{name = $group.name; description = $group.description}
try {
$oktaGroup = New-OktaGroup @{profile = $profile} # <---- SEE HERE
$message = "New group"
} catch {
Get-Error $_
try {
$oktaGroup = Get-OktaGroups $group.name 'type eq "OKTA_GROUP"'
$message = "Found group"
} catch {
Get-Error $_
$oktaGroup = $null
$message = "Invalid group"
}
}
$importedGroups += [PSCustomObject]@{id = $oktaGroup.id; name = $group.name; message = $message}
}
$importedGroups | Export-Csv importedGroups.csv -notype
"$($groups.count) groups read."
}
any suggestions appreciated !!
from oktaapi.psm1.
the header line in csv has to match the code that reads the CSV:
# Sample groups.csv file with 2 fields. Make sure you include the header line as the first record.
# name,description
# PowerShell Group,Members of this group are awesome.
has to match this
$profile = @{name = $group.name; description = $group.description}
your file is using group description
. change it to description
and see if it works better.
from oktaapi.psm1.
from oktaapi.psm1.
You said "it's not working". I would need more information in order to help you.
Are getting an error? If so, what is it? Is it doing anything? Are you calling the New-Groups
function? You've defined it, but I don't see where you're calling it. Is there more code?
from oktaapi.psm1.
from oktaapi.psm1.
from oktaapi.psm1.
It looks like Get-Error
code no longer works. in Windows PowerShell 5, i get nothing. In PowerShell 6/7, I get an error.
I don't have time to fix this now.
I suggest you re-write the code. Here are two approaches:
- if you get an error, just continue, or
- search for the group. If it exists, skip it. If it doesn't exist, import it. this is slower than approach 1, but won't create errors
Unless you're finding other problems with my module, I'm going to close this issue. If you need additional help writing your code, I'm available at an hourly rate.
from oktaapi.psm1.
from oktaapi.psm1.
from oktaapi.psm1.
OktaAPI.psm1/Modules/OktaAPI.psm1
Lines 269 to 271 in 71f1dac
OktaAPI.psm1/Modules/OktaAPI.psm1
Lines 179 to 181 in 71f1dac
There are no bulk operations in the API as far as I know. You can check the documentation. Otherwise you'll have to call these functions in a loop.
from oktaapi.psm1.
See also
Lines 314 to 347 in 71f1dac
from oktaapi.psm1.
Related Issues (18)
- (400) Bad Request HOT 3
- Get-OktaUserGroups doesn't support paginated return HOT 2
- License HOT 3
- Invoke-RestMethod 400 Bad Request HOT 1
- Re-Activate User by ID HOT 1
- Get-OktaUser Exception thrown ?? HOT 6
- Query : What is $group ? OktaAPI.psm1/Modules/OktaAPI.psm1 : Line 82 HOT 3
- Query - New Group Rules HOT 9
- Import existing users to single group via CSV? HOT 16
- API key question HOT 6
- Can Fetching limit be increased for Get-OktaUsers Function ? HOT 1
- Using bearer tokens in Connect-Okta HOT 10
- Map existing application and group in okta HOT 1
- Getting next page of logs HOT 1
- Tip for Managing IDs
- New-OktaGroup HOT 8
- Invoke-Webrequest fails on powershell 5 and below on a machine without IE or a user that has never run it HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oktaapi.psm1.