Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

call saviynt data via powershell script

musthak_ahamad
Regular Contributor
Regular Contributor

Hi 

we have a requirement to fetch the list if users who have customproperty4=true from saviynt via powershell script and store the results in windows server in csv format. the powershell script will run from windows server and the script should use saviynt api to query the data. 

have anyone done this implementation?

4 REPLIES 4

adriencosson
Valued Contributor
Valued Contributor

Hi @musthak_ahamad ,

I generated this script to get you started with Powershell elements to : 

  • Authenticate on Saviynt
  • Use the access token to get users with the appropriate filter
  • Loop through users results to store them in a csv file

Adjust the URLs, username and password according to your environment, and refine the code with the below documentation.

https://documenter.getpostman.com/view/23973797/2s9XxwutWR 

Hope this helps !

Regards,
Adrien COSSON

thanks for you support i will test this and let you know.

musthak_ahamad
Regular Contributor
Regular Contributor

Hi  Adriencosson,

thanks for the script but i got stuck at the for each loop , before the loop am able to get the multiple user details but not able to print it ,i have attached the script here ,

am getting the reponse of the result  like below

User response @{msg=Successful; displaycount=2; totalcount=2; userdetails=System.Object[]; errorCode=0; statusCode=200}

but the foreachloop is not looping the value to print it . but if i give the date with array it works by printing one value.

foreach ($user in $userResponse) {
$userData = [PSCustomObject]@{
Name = $user.userdetails.[0].username
# Email = $user.Email
# CustomProperty4 = $user.CustomProperty4
# Add more properties as needed
}

$userDataArray += $userData
}

# Export user data to a CSV file
$userDataArray | Export-Csv -Path "SaviyntUsers.csv" -NoTypeInformation

Write-Host "User data has been exported to SaviyntUsers.csv" $userDataArray

adriencosson
Valued Contributor
Valued Contributor

Hi @musthak_ahamad ,

As you may have noticed from the Saviynt documentation, the response of the retrieved users' details is in "userdetails" if you use the "/getUser" API. 

adriencosson_1-1694037213936.png

That being said, if you store your response of the API call in $userResponse variable, you need to loop over the "userdetails" list to retrieve the data.

I attached a sample below to convert the response into JSON format and loop through the same list.

Please let us know if this helps.

Note : The API can retrieve a maximum of 500 users (using /getUser?max=500) per call. If you have more identities, you also may want to :

  • Update your Get-Users method to create a $noOfResults variable that will increment based on the "displaycount" value of the response (or simply +500 per call)
  • Create a $totalCount variable based on the "totalcount" value of the response
  • Loop over the Get-Users method while $noOfResults < $totalCount

 

 

Regards,
Adrien COSSON