public override void ExecuteCmdlet()
        {
            var userCreateparameters = new UserCreateParameters
            {
                AccountEnabled = true,
                DisplayName = DisplayName,
                PasswordProfile = new PasswordProfile
                {
                    Password = Password,
                    ForceChangePasswordNextLogin = ForceChangePasswordNextLogin.IsPresent ? true : false
                },
                UserPrincipalName = UserPrincipalName
            };

            if(!string.IsNullOrEmpty(ImmutableId))
            {
                userCreateparameters.ImmutableId = ImmutableId;
            }

            ExecutionBlock(() =>
            {
                if (ShouldProcess(target: UserPrincipalName, action: string.Format("Adding a new user with UPN '{0}'", UserPrincipalName)))
                {
                    WriteObject(ActiveDirectoryClient.CreateUser(userCreateparameters));
                }
            });
        }
 /// <summary>
 /// Create a new user.  (see
 /// http://msdn.microsoft.com/en-us/library/azure/dn130117.aspx for
 /// more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Graph.RBAC.IUserOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create a user.
 /// </param>
 /// <returns>
 /// Server response for Get user information API call
 /// </returns>
 public static UserGetResult Create(this IUserOperations operations, UserCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IUserOperations)s).CreateAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public void RaUserPermissions()
        {
            User newUser = null;
            ResourceGroup resourceGroup = null;
            string roleAssignmentId = "1BAF0B29-608A-424F-B54F-92FCDB343FFF";
            string userName = null;
            string userPass = null;
            string userPermission = "*/read";
            string roleDefinitionName = "Reader";

            var controllerAdmin = ResourcesController.NewInstance;

            // Generate new user under admin account
            controllerAdmin.RunPsTestWorkflow(
                // scriptBuilder
                () =>
                {
                    userName = TestUtilities.GenerateName("aduser");
                    userPass = TestUtilities.GenerateName("adpass") + "0#$";

                    var upn = userName + "@" + controllerAdmin.UserDomain;

                    var parameter = new UserCreateParameters
                    {
                        UserPrincipalName = upn,
                        DisplayName = userName,
                        AccountEnabled = true,
                        MailNickname = userName + "test",
                        PasswordProfile= new PasswordProfile
                        {
                            ForceChangePasswordNextLogin = false,
                            Password = userPass
                        }
                    };

                    newUser = controllerAdmin.GraphClient.Users.Create(parameter);

                    resourceGroup = controllerAdmin.ResourceManagementClient.ResourceGroups
                                        .List()
                                        .First();

                    // Wait to allow newly created object changes to propagate
                    TestMockSupport.Delay(20000);

                    return new[]
                    {
                        string.Format(
                            "CreateRoleAssignment '{0}' '{1}' '{2}' '{3}'",
                                roleAssignmentId,
                                newUser.ObjectId,
                                roleDefinitionName,
                                resourceGroup.Name)
                    };
                },
                // initialize
                null,
                // cleanup 
                null,
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName() + "_Setup");

            // login as different user and run the test
            var controllerUser = ResourcesController.NewInstance;
            controllerUser.RunPsTestWorkflow(
                // scriptBuilder
                () =>
                {
                    return new[]
                    {
                        string.Format(
                            "Test-RaUserPermissions '{0}' '{1}'",
                            resourceGroup.Name,
                            userPermission)
                    };
                },
                // initialize
                (testFactory) =>
                {
                    if (newUser != null)
                    {
                        testFactory.CustomEnvValues[TestEnvironment.UserIdKey] = userName + "@" + controllerAdmin.UserDomain;
                        testFactory.CustomEnvValues[TestEnvironment.AADPasswordKey] = userPass;
                    }
                },
                // cleanup 
                null,
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName() + "_Test");

            // remove created user
            controllerAdmin = ResourcesController.NewInstance;
            controllerAdmin.RunPsTestWorkflow(
                // scriptBuilder
                null,
                // initialize
                null,
                // cleanup 
                () =>
                {
                    if (newUser != null)
                    {
                        controllerAdmin.GraphClient.Users.Delete(newUser.ObjectId);
                    }
                    controllerAdmin.AuthorizationManagementClient.RoleAssignments.Delete(resourceGroup.Id, new Guid(roleAssignmentId));
                },
                TestUtilities.GetCallingClass(),
                TestUtilities.GetCurrentMethodName() + "_Cleanup");
        }
예제 #4
0
        public User CreateUser()
        {
            string username = TestUtilities.GenerateName("aduser");
            string upn = username + "@" + Domain;

            UserCreateParameters parameter = new UserCreateParameters();
            parameter.UserPrincipalName = upn;
            parameter.DisplayName = username;
            parameter.AccountEnabled = true;
            parameter.MailNickname = username + "test"; 
            parameter.PasswordProfileSettings = new UserCreateParameters.PasswordProfile();
            parameter.PasswordProfileSettings.ForceChangePasswordNextLogin = false;
            parameter.PasswordProfileSettings.Password = "******";

            return GraphClient.User.Create(parameter).User;
        }
 public PSADUser CreateUser(UserCreateParameters userCreateParam)
 {
         return GraphClient.Users.Create(userCreateParam).ToPSADUser();
 }
        private User CreateNewAdUser(ResourcesController controllerAdmin)
        {
            var name = TestUtilities.GenerateName("aduser");
            var parameter = new UserCreateParameters
            {
                DisplayName = name,
                UserPrincipalName = name + "@" + controllerAdmin.UserDomain,
                AccountEnabled = true,
                MailNickname = name + "test",
                PasswordProfileSettings = new UserCreateParameters.PasswordProfile
                {
                    ForceChangePasswordNextLogin = false,
                    Password = TestUtilities.GenerateName("adpass") + "0#$"
                }
            };

            return controllerAdmin.GraphClient.User.Create(parameter).User;
        }
 /// <summary>
 /// Create a new user.  (see
 /// http://msdn.microsoft.com/en-us/library/azure/dn130117.aspx for
 /// more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Graph.RBAC.IUserOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create a user.
 /// </param>
 /// <returns>
 /// Server response for Get user information API call
 /// </returns>
 public static Task<UserGetResult> CreateAsync(this IUserOperations operations, UserCreateParameters parameters)
 {
     return operations.CreateAsync(parameters, CancellationToken.None);
 }