I needed to create this command in order to solve an odd permissions problem that I was experiencing. I had a web application (http://teamsites) which I’d setup and needed to start migrating sites to. When I went to create the site collection using createsite I got the following error: "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" (I got the same "Access is Denied" error when I attempted this via central admin). After doing some digging I found that I could successfully create the site collection from the web application itself (not central admin or stsadm) (the site owner was the logged in user in this case). I also found that I could create the site via stsadm and central admin as long as the owner account was the same as my currently logged in admin account. If I specified an account other than the current user then an access denied error would come up. I then assigned the current user "Full Control" via the policy for web applications in central admin and found that I could now create sites collections and specify any user as the owner. So for some reason assigning my admin account the Full Control policy for the web application is what allows me to create a site collection and specify a user other than the logged in user. I find this really odd as it seems like a farm admin account should be able to do this just fine. Now that I knew how to solve the problem I needed a command to make this setting so that it would be part of my upgrade script: gl-adduserpolicyforwebapp. To make this change it’s a simple matter of grabbing an SPPolicyCollection object and calling the Add() method passing in the user login and display name. Once the policy object is created (SPPolicy) you can then bind the permissions to it using the PolicyRoleBindings property and calling the Add method (passing in the SPPolicy object created previously):
The syntax of the command can be seen below:
C:\>stsadm -help gl-adduserpolicyforwebapp stsadm -o gl-adduserpolicyforwebapp Adds a user policy for a web application. Parameters: -url <web application url> -zone <default | intranet | internet | custom | extranet | all> -userlogin <DOMAIN\user> -username <display name> -permissions <comma separated list of policy permissions>
Here’s an example of how to add a policy giving a SharePoint administrators group full control to a web application:
stsadm -o gl-adduserpolicyforwebapp -url "http://intranet" -zone all -userlogin "domain\spadmins" -username "SharePoint Administrators" -permissions "Full Control"