Powershell Script to receive access token

Hello everyone,

I am currently working on a Powershell Script to retrieve a token from Keycloak to authenticate to an application afterwards. So far I wasn’t able to find any libraries or solutions in www.

Additional and maybe necessary Info.
The Script will be executed by users so they will be prompted to enter their User Credentials.

Kind regards and thanks for your help
P3RF3CTION

I meanwhile solved the Problem.
Providing an example down here now:

###############################################
###                                                                                ####
### Basic Auth Script against Keyclaok                       ####
###                                                                                ####
###                                                                                ####
###############################################

# Setting Variables and Credentials

$Keycloak_Server = "https://{{servername}}"
$credentials = Get-Credential -Message "Please enter your KC Credentials"
$Username = $credentials.UserName 
$Password = $credentials.GetNetworkCredential().Password


$RequestURL = $Keycloak_Server + "/auth/realms/master/protocol/openid-connect/token"


$body = @{grant_type='password'
      username=$Username
      password=$Password
      client_id='{{your_client_id}}'
      client_secret='{{your_client_secret}}'
      }

# Token Request

$result = Invoke-WebRequest -Method POST -Uri $RequestURL -ContentType "application/x-www-form-urlencoded" -Body $body -Credential $credentials
Write-Output $result