As many of you know, it's easy to share your ArcGIS Server service to ArcGIS Online/Portal for ArcGIS when you are publishing the service. One thing that I don't find so easy is adding individual layers from this service as items to AGOL/Portal. For example, say I am publishing the following MXD to ArcGIS Server:
You can see the MXD contains 9 different layers. When sharing this service with AGOL/Portal, it will create a single Map Image Layer:
When adding this layer to a web map, it will bring in all 9 layers. Say I am only interested in adding one of these layers, i.e. Rivers. I would have to remove all the other layers in the web map, or I can add the individual layer as an item to AGOL/Portal using the REST URL and the corresponding index number, ex:
https://ags.esri.com/arcgis/rest/services/Philadelphia/MapServer/5
The layer will then be added as a Feature Layer to AGOL/Portal:
The rivers layer is now discoverable within my AGOL/Portal Organization and can be easily added as an individual layer to a web map. However, you can see that this can be time consuming to add all 9 layers as items to your Organization. The attached GP tool will do this automatically for you. Ex:
After the tool is executed, the individual layers are all added as Feature Layers within AGOL/Portal:
Some may question why not just publish all 9 layers as individual ArcGIS Server service. This is a feasible workflow, but one thing to keep in mind is that this would consume more resources on your ArcGIS Server instance. For example, below is the CPU and Memory usage when only the single service is published:
Compare this to the CPU and Memory when all 9 layers are published as services. There is a slight increase in both: