Skip to content

Instantly share code, notes, and snippets.

@erichannell
Created July 12, 2017 19:28
Show Gist options
  • Save erichannell/0eab577a88a33caf1b93853fbff5fb70 to your computer and use it in GitHub Desktop.
Save erichannell/0eab577a88a33caf1b93853fbff5fb70 to your computer and use it in GitHub Desktop.
migrate users between servers
# -*- coding: utf-8 -*-
import tableauserverclient as TSC
# migrate from
site = ""
user = ""
pwd = ""
tableau_auth = TSC.TableauAuth(user, pwd, site_id=site)
server = TSC.Server('https://dub01.online.tableau.com')
users_to_migrate = []
print "migrating users from:", site
print '*' * 25
with server.auth.sign_in(tableau_auth):
# get a list of all users
all_users, pagination_item = server.users.get()
print "There are {} user on site".format(pagination_item.total_available)
for i, user in enumerate(all_users):
print "{} {} ({})".format(i + 1, user.name, user.site_role)
# skip the admin
if 'Administrator' not in user.site_role:
users_to_migrate.append(user)
print "migrating {} users (skipping admins)".format(len(users_to_migrate))
print '*' * 25
# migrate to
site = ""
user = ""
pwd = ""
print "migrating users to:", site
tableau_auth = TSC.TableauAuth(user, pwd, site_id=site)
server = TSC.Server('https://dub01.online.tableau.com')
with server.auth.sign_in(tableau_auth):
for i, user in enumerate(users_to_migrate):
# create user
new_user = TSC.UserItem(user.name, 'Viewer')
# add new user
new_user = server.users.add(new_user)
print "{} {} ({})".format(i+1, new_user.name, new_user.site_role)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment