-
1. Re: Automatically add all Site Admins to a user group
Jeff StraussOct 26, 2017 7:42 AM (in response to Elizabeth Shelley)
One possible option is to leverage tabcmd addusers and place this into a script that is triggered via task scheduler tabcmd Commands
What you need to do first though is query the database to get a list of all siteusers, then use tabcmd export to get this into a csv format that then will flow into the addusers.
-
2. Re: Automatically add all Site Admins to a user group
Glen Robinson Oct 27, 2017 12:53 AM (in response to Elizabeth Shelley)Hi Elizabeth
Below is some powershell scripting, which uses REST API to create a group "SiteAdmins" and add all users on that site who have that role to the group
You will need to update server name, user , site, etc
The script assumes that the group doesnt exist, and will fail if it does. Could add some code to check for group, if that is useful to you..
to run, save the script as *.ps1, and run in powershell on a windows machine.
Anyway, hope this helps
All the best
Glen
$server = "http://localhost"
$username = "glen"
$password = "password"
$siteID =""
# Login to Server
# generate body for sign in
$signin_body = (’<tsRequest>
<credentials name=“’ + $username + ’” password=“’+ $password + ’” >
<site contentUrl="’ + $siteID +’"/>
</credentials>
</tsRequest>’)
$Uri = "$server/api/2.7/auth/signin"
$response = Invoke-RestMethod -Uri $uri -Body $signin_body -Method Post
# get the auth token, site id and my user id
$authToken = $response.tsResponse.credentials.token
$siteID = $response.tsResponse.credentials.site.id
$headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$headers.Add(“X-Tableau-Auth”, $authToken)
$authToken
$siteID
$GroupName = "SiteAdmins"
#Create SiteAdminsGroup
$body = ('<tsRequest><group name="' + $GroupName + '" /></tsRequest>')
$response = Invoke-RestMethod -Uri $server/api/$api_ver/sites/$siteID/groups -Headers $headers -Method POST -Body $body
$GroupID = $response.tsResponse.group.id
$GroupID
#List Users who are Site Admins
$response = Invoke-RestMethod -Uri $server/api/$api_ver/sites/$siteID/users?filter=siteRole:eq:SiteAdministrator -Headers $headers -Method Get
ForEach ($user in $response.tsResponse.Users.User)
{
$user.ID
#Add users to Group
$body = ('<tsRequest><user id="' + $user.ID + '" /></tsRequest>')
$response = Invoke-RestMethod -Uri $server/api/$api_ver/sites/$siteID/groups/$GroupID/users -Headers $headers -Method POST -Body $body
$response.tsResponse.user
}
# Sign Out of Server
$response = Invoke-RestMethod -Uri $server/api/2.7/auth/signout -Headers $headers -Method Post
-
3. Re: Automatically add all Site Admins to a user group
Elizabeth Shelley Oct 31, 2017 7:21 AM (in response to Elizabeth Shelley)Thanks both, will have a chat internally to see which way we want to proceed.