<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is there a way to programmatically change all services on a server to shared from dedicated? in Publishing and Managing Services Questions</title>
    <link>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1088514#M511</link>
    <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous User,&lt;/P&gt;&lt;P&gt;You can use the &lt;A href="https://developers.arcgis.com/rest/enterprise-administration/server/change-provider.htm" target="_self"&gt;Change Provider&lt;/A&gt; operation.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Aug 2021 16:23:10 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-08-12T16:23:10Z</dc:date>
    <item>
      <title>Is there a way to programmatically change all services on a server to shared from dedicated?</title>
      <link>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1088471#M510</link>
      <description>&lt;P&gt;ArcGIS server 10.8.1&lt;/P&gt;&lt;P&gt;I have well over 200 services in my testing environment.&amp;nbsp; I would like to change them all to shared.&amp;nbsp; Is there a way using notebook?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 15:29:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1088471#M510</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-12T15:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to programmatically change all services on a server to shared from dedicated?</title>
      <link>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1088514#M511</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous User,&lt;/P&gt;&lt;P&gt;You can use the &lt;A href="https://developers.arcgis.com/rest/enterprise-administration/server/change-provider.htm" target="_self"&gt;Change Provider&lt;/A&gt; operation.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 16:23:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1088514#M511</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-08-12T16:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to programmatically change all services on a server to shared from dedicated?</title>
      <link>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1089614#M519</link>
      <description>&lt;P&gt;&lt;SPAN&gt;This operation is used to update an individual service to use either a dedicated or shared instance type is right in the documentation and I see no way to do multiple.&amp;nbsp; One at at time is just as easily completed using the server manager.&amp;nbsp; Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 14:55:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1089614#M519</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-17T14:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to programmatically change all services on a server to shared from dedicated?</title>
      <link>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1089897#M520</link>
      <description>&lt;P&gt;@Anonymous User&amp;nbsp;Yes, you will need to iterate through each service, check if it's dedicated, and then update the provider if it is using the ChangeProvider operation.&amp;nbsp; Ex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests, json

# Variables
username = 'siteadmin'
password = 'siteadmin'
server = "ags.esri.com"

# Disable warnings
requests.packages.urllib3.disable_warnings()

# Function to change provider
def changeProvider():
    print("\tChanging provider")
    url = serviceURL + '/changeProvider'
    params = {'f': 'pjson', 'token': token, 'provider': 'DMaps'}
    r = requests.post(url, data=params, verify=False)
    response = json.loads(r.content)
    print(f"\t{response['status']}")

# Generate ArcGIS Server Token
tokenURL = f'https://{server}:6443/arcgis/admin/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'client': 'requestip'}
r = requests.post(tokenURL, data=params, verify=False)
response = json.loads(r.content)
token = response['token']

# Query AGS service propoerties in ROOT
baseUrl = f'https://{server}:6443/arcgis/admin/services'
params = {'f': 'pjson', 'token': token}
r = requests.post(baseUrl, data=params, verify=False)
catalog = json.loads(r.content)
services = catalog['services']
for service in services:
    if service['type']!= 'StreamServer' and service['type'] != 'GPServer':
        params = {'f': 'pjson', 'token': token}
        serviceURL = f"{baseUrl}/{service['serviceName']}.{service['type']}"
        r = requests.post(serviceURL, data=params, verify=False)
        response = json.loads(r.content)
        # Check if provider is dedicated
        if response['provider'] == 'ArcObjects11':
            # Execute function to change provider
            print(f"{service['serviceName']} is dedicated")
            changeProvider()

# Query AGS service propoerties in folders
folders = catalog['folders']
for folderName in folders:
    if str(folderName) not in ('Hosted', 'System', 'Utilities', 'DataStoreCatalogs'):
        baseUrl = f'https://{server}:6443/arcgis/admin/services/{folderName}'
        params = {'f': 'pjson', 'token': token}
        r = requests.post(baseUrl, data=params, verify=False)
        catalog = json.loads(r.content)
        services = catalog['services']
        for service in services:
            if service['type'] != 'StreamServer' and service['type'] != 'GPServer':
                serviceURL = f"{baseUrl}/{service['serviceName']}.{service['type']}"
                r = requests.post(serviceURL, data=params, verify=False)
                response = json.loads(r.content)
                if response['provider'] == 'ArcObjects11':
                    # Execute function to change provider
                    print(f"{service['serviceName']} is dedicated")
                    changeProvider()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 11:28:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/publishing-and-managing-services-questions/is-there-a-way-to-programmatically-change-all/m-p/1089897#M520</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-08-18T11:28:50Z</dc:date>
    </item>
  </channel>
</rss>

