mbegan / Okta-PSModule

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

Can we "oktaUpdateUserbyID" for SecondEmail attribute? #20

Closed noeffort3 closed 6 years ago

noeffort3 commented 6 years ago

Hi Matt,

"Me" again :)

I have a request for a scripted approach to input/update the "secondEmail" for a bulk of users (44, so certainly non-trivial).

However, I only see the basic "identifying" attributes available to be "updated" via oktaUpdateUserByID call in OTKA.psm1.

I think I remember though, you showing me how you could upload a "newprofile" via oktaChangeProfileByID, or other same such call. If so, I would imagine I could upload a "newprofile" including the secondEmail, but... I believe also, I would need to first grab the current profile, build the hashtable, and then insert the secondEmail as a new/updated attribute in the "newprofile", yes?

Would be nicer to only "just" update the one singular attribute but I think as I said, I am remembering that was not an option and you would have to re-send the entire current profile, with the new attribute additionally... is that correct?

Cheers from P.A.! Kind Regards,

mbegan commented 6 years ago

Use oktaUpdateUserProfilebyID

oktaUpdateUserProfilebyID -uid -partial -Profile @{secondEmail="secondemail@domain.tld"}

-uid is the oktaid of the user you want to update -profile is an object describing any attribute(s) and values you want to updated/define -partial is a switch to change the update from a full update (put) to a partial update (post)

PS > Import-Module Okta                                                                                                                                                             
PS > $u = oktaGetUserbyID -userName matt.egan                                                                                                                                       
PS > $u.profile                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       lastName        : Egan                                                                                                                                                                                   
login           : matt.egan@okta.com
firstName       : Matthew
email           : matt.egan@okta.com

PS > oktaUpdateUserProfilebyID -uid $u.id -partial -Profile @{secondEmail="secondemail@domain.tld"} -Verbose                                                                        
VERBOSE: {
  "profile": {
    "secondEmail": "secondemail@domain.tld"
  }
}
VERBOSE: POST https://mattegantest.oktapreview.com/api/v1/users/00uabxx4hlwm47RSV0h7 with 66-byte payload
VERBOSE: received -byte response of content type application/json
VERBOSE: Req-Hdr: Accept-Charset -> ISO-8859-1,utf-8                                                                                                                                                     VERBOSE: Req-Hdr: Accept-Encoding -> deflate,gzip                                                                                                                                                        VERBOSE: Req-Hdr: Authorization -> SSWS xXxXxXxxXxxXxXxXxxXx                                                                                                                                             VERBOSE: Req-Hdr: Accept-Language -> en-US                                                                                                                                                               
VERBOSE: Req-Hdr: Content-Type -> application/json
VERBOSE: Req-Hdr: User-Agent -> Okta-PSModule/2.4 (6.0.0-rc) (Unix) (Darwin 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64)
VERBOSE: Res-Hdr: Date -> Mon, 19 Mar 2018 21:58:19 GMT
VERBOSE: Res-Hdr: X-Okta-Request-Id -> WrAye0xKSNIHADcZF@LdcgAAF7Y
VERBOSE: Res-Hdr: X-Rate-Limit-Limit -> 600
VERBOSE: Res-Hdr: X-Rate-Limit-Remaining -> 597
VERBOSE: Res-Hdr: X-Rate-Limit-Reset -> 1521496723
VERBOSE: Res-Hdr: Content-Type -> application/json; charset=UTF-8
VERBOSE: Okta Request ID: WrAye0xKSNIHADcZF@LdcgAAF7Y
VERBOSE: There was content retured, convert from json string
VERBOSE: You have 597 out of 600 aka: 99.500% left in the tank
VERBOSE: This Page returned: 1, we've seen: 1 results so far
VERBOSE: We see no or an invalid next link of: False

PS > $u2.profile                                                                                                                                                                    
lastName        : Egan                                                                                                                                                                                   
login           : matt.egan@okta.com
firstName       : Matthew
email           : matt.egan@okta.com
secondEmail     : secondemail@domain.tld
noeffort3 commented 6 years ago

Thanks Matt, I just tested it, and was able to update OKTA secondaryEmail address in a test on devqa. It was a breeze. Cheers!