09/01/2023 03:09 PM
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?
09/02/2023 12:31 PM
Hi @musthak_ahamad ,
I generated this script to get you started with Powershell elements to :
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 !
09/02/2023 01:17 PM
thanks for you support i will test this and let you know.
09/06/2023 11:20 AM
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
09/06/2023 03:06 PM
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.
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 :