How to automatically create a node for each user and set the user as author of the node? I have 50 users on my site. I want to create 50 nodes and then set the author of the node to each of my 50 users.

Is there a way to do this using a module or programmatically, rather than having to first create all the 50 nodes and then editing the author fields?
Step 1

Use the Rules module to create a Rules Component, which includes whatever Rules Conditions you might need (if any), and with a Rules Action to Create an entity (of type node). Make sure to use a parameter (of type "integer"), and which you use as the value to be assigned for the "author" of the node to be created. Here is an example of such Rules Component (in Rules export format, if you have the Rules UI enabled you should be able to import it in your own site):

{ "rules_create_a_new_node" : {
    "LABEL" : "Create a new node",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "uid_of_author" : { "label" : "Uid of the user to be used as author", "type" : "integer" } },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "3" : "3" } }
        }
      }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "user", "id" : [ "uid-of-author" ] },
          "PROVIDE" : { "entity_fetched" : { "user_fetched" : "Fetched user" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "page",
            "param_title" : "Node created for user [user-fetched:name]",
            "param_author" : [ "user-fetched" ]
          },
          "PROVIDE" : { "entity_created" : { "node_created" : "Created node" } }
        }
      },
      { "drupal_message" : { "message" : "Node creation completed for user with name \u0022[user-fetched:name]\u0022." } }
    ]
  }
}


Some details about the above Rules Component:


It checks if the user using it, has role "admin" (just to be secure it a bit, feel free to omit that if you don't want that).
It fetched the info about the user for which the uid was entered as a parameter.
It creates a node of type (machine name) page (adapt that to whatever machine name fits for you).
It shows a Drupal message to confirm the node got created (just for testing, remove it if you don't need it anymore).


After you imported the above Rules component, use the "execute" link in front of this Rules Component to QA-test your component (for which you'll need to enter an appropriate uid value for the author you want). After it completes, it'll show an informational Drupal message similar to this one (with Demo.User = the name of the user for which I entered the uid):


  Node creation completed for user with name "Demo.User".


Step 2

Create a view of the group of users for which those nodes should be created. Then transform that view into a view that uses Views Bulk Operations, and use the technique documented in "How to use Rules to create a custom bulk operation for a VBO view?". In doing so, you'll then be able to use the Rules Component from Step 1. Make sure one of the fields (columns) in your VBO view is the uid for each of the (50) users for which you want to create such node.

Tutorial

To get the idea, have a look at the video about Using Rules components with VBO" which uses a Rules Component with (only) 1 parameter. If you want even more, then also watch the subsequent "Using Rules components with more than one parameter" video.

Attention: to process like 100.000 entities at once is quite a challenge (memory requirements, etc). Therefor you might want to also watch the video about "More details about VBO settings" ... Before you are tempted to use VBO for processing them all at once ...

PS: no need for custom code ...