使用powershell在sitecore中创建用户

时间:2017-04-07 20:01:38

标签: sitecore

问题:我想使用Microsoft powershell脚本在sitecore中创建用户。我不想使用sitecore提供的powershell。

我可以在sitecore中使用powershell脚本创建用户。但要求是在进行设置时使用PowerShell脚本在每个环境中创建新用户。

2 个答案:

答案 0 :(得分:0)

Sitecore用户是Sitecore核心SQL数据库中的普通ASP.NET成员资格用户。 (默认值,但取决于您的配置)。在Microsoft PowerShell中,您可以执行SQL查询。

首先使用存储过程aspnet_Membership_CreateUser创建用户,并将其用作ApplicationName' sitecore'并使用sitecore域。

此SQL创建有效的Sitecore用户:

declare @salt nvarchar(128)
declare @password varbinary(256)
declare @input varbinary(512)
declare @hash varchar(64)

-- Change these values (@salt should be Base64 encoded)
set @salt = N'eyhKDP858wdrYHbBmFoQ6DXzFE1FB+RDP4ULrpoZXt6f'
set @password = convert(varbinary(256),N'mypassword')

set @input = hashbytes('sha1',cast('' as  xml).value('xs:base64Binary(sql:variable(''@salt''))','varbinary(256)') + @password)
set @hash = cast('' as xml).value('xs:base64Binary(xs:hexBinary(sql:variable(''@input'')))','varchar(64)')

-- @hash now contains a suitable password hash
-- Now create the user using the value of @salt as the salt, and the value of @hash as the password (with the @PasswordFormat set to 1)

DECLARE @return_value int, 
  @UserId uniqueidentifier 

EXEC @return_value = [dbo].[aspnet_Membership_CreateUser] 
  @ApplicationName = N'sitecore', 
  @UserName = N'sitecore\startup', 
  @Password = @hash, 
  @PasswordSalt = @salt, 
  @Email = N'jan@test.com', 
  @PasswordQuestion = N'nope', 
  @PasswordAnswer = N'nope', 
  @IsApproved = 1, 
  @CurrentTimeUtc = '2017-03-03', 
  @CreateDate = '2017-03-03', 
  @UniqueEmail = 1, 
  @PasswordFormat = 1, 
  @UserId = @UserId OUTPUT 

SELECT @UserId as N'@UserId' 

SELECT 'Return Value' = @return_value 

并添加您需要的rols。 ' sitecore \ Sitecore客户端用户'是您登录CMS时需要的rol。

EXECUTE [dbo].[aspnet_UsersInRoles_AddUsersToRoles] 
   @ApplicationName  = N'sitecore'
  ,@UserNames =  N'sitecore\startup'
  ,@RoleNames =  N'sitecore\Sitecore Client Users'
  ,@CurrentTimeUtc =  N'2017-03-03'
GO

此示例创建用户“启动”。密码' mypassword'最小的权利。

答案 1 :(得分:0)

您现在可以使用Sitecore Powershell extensions to create users in Sitecore

示例

PS master:\> New-User -Identity michael -Enabled -Password b -Email batman@gmail.com -FullName "Bruce Wayne"

相关问题