How to create Multiple Uses in Perforce

Viewed 20

Is there a way we (superAdmin) can create multiple users with their email addresses in Perforce, either using the command line or using scipt (python or shell)?

Shell script would be preferred.

1 Answers

Use the p4 user -o command to output a user spec, and p4 user -i (with the -f flag if your server is configured to require superuser permission to create new users) to save it.

The email address defaults to user@client so an easy way to set the email address without actually editing the form is to just specify the email domain as the client name (you don't need to create an actual client spec) via the -c global flag, e.g.:

C:\Perforce\test>p4 -c gmail.com user -o fred
# A Perforce User Specification.
#
#  User:        The user's user name.
#  Type:        Either 'service', 'operator', or 'standard'.
#               Default: 'standard'. Read only.
#  Email:       The user's email address; for email review.
#  Update:      The date this specification was last modified.
#  Access:      The date this user was last active.  Read only.
#  FullName:    The user's real name.
#  JobView:     Selects jobs for inclusion during changelist creation.
#  Password:    If set, user must have matching $P4PASSWD on client.
#  AuthMethod:  'perforce' if using standard authentication or 'ldap' if
#               this user should use native LDAP authentication.
#  Reviews:     Listing of depot files to be reviewed by user.

User:   fred

Email:  fred@gmail.com

FullName:       fred

Piping this output to p4 user -i -f saves the user spec:

C:\Perforce\test>p4 -c gmail.com user -o fred | p4 user -i -f
User fred saved.

C:\Perforce\test>p4 users fred
fred <fred@gmail.com> (fred) accessed 2022/09/21

If you need to edit the actual form (e.g. to set the FullName), you can always use text editing tools like sed, but an easier option is to use the built-in --field global flag, which lets you set individual spec fields in command output:

C:\Perforce\test>p4 --field Email=fred@bedrock.gov --field "FullName=Fred Flintstone" user -o fred
User:   fred

Type:   standard

Email:  fred@bedrock.gov

Update: 2022/09/21 08:50:34

Access: 2022/09/21 08:50:34

FullName:       Fred Flintstone

AuthMethod:     perforce

Again, to actually save the user spec you just need to pipe this to p4 user -i:

C:\Perforce\test>p4 --field Email=fred@bedrock.gov --field "FullName=Fred Flintstone" user -o fred | p4 user -if
User fred saved.

C:\Perforce\test>p4 users fred
fred <fred@bedrock.gov> (Fred Flintstone) accessed 2022/09/21
Related