<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D50Z00008G7VZ3SANOkta Classic EngineIntegrationsAnswered2024-04-30T09:18:25.000Z2018-04-16T19:13:16.000Z2018-08-12T04:17:02.000Z
Powershell script for adding groups to applications? (Migrating domains)
So, we're migrating domains and I would like to add the equivalent groups from the new domain to the apps the groups from the old domain are already assigned... I've got this script together and logically it makes sense... I have a csv file with the appId and groupId I want assigned to that app. However, running the script gives me a 404 error. Can someone point out what it appears that I'm doing wrong with it?: 
  1.  # Define headers for web request $headers = @{"Authorization" = "SSWS <token>"; "Accept" = "application/json"; "Content-Type" = "application/json"} # Import .csv from the location on computer $csv = Import-Csv <location of .csv file> -Header "applicationId","groupId" # This allows the variables to be pulled. The top of each column in the .csv needs to correspond with these line mapping names. The names in this script are applicationId and groupId. foreach ($line in $csv) {  try {  # Add the group to the app using the groupId and stop processing if it fails  $result = Invoke-WebRequest -Headers $headers -Method Put -uri "https://<company>.okta.com/api/v1/apps/$line.applicationId/groups/$line.groupId" -ErrorAction:Stop  # Write message if adding the group to the app was successful  if ( $result.StatusCode -eq 204 ) { Write-Output "Successfully added $($line.groupId)" }  } catch {  # Write message if adding the group to the app fails  Write-Output "Failed adding group $($line.groupId) to app $($line.applicationId) - error: $($_.Exception.Response.StatusCode.Value__)"  } }
 Thanks!


This question is closed.
Loading
Powershell script for adding groups to applications? (Migrating domains)