0
问题:我想使用Microsoft PowerShell脚本在sitecore中创建用户。我不想使用sitecore提供的powershell。使用powershell在sitecore中创建用户
我能够在sitecore内使用PowerShell脚本创建用户。但要求是在安装时使用PowerShell脚本在每个环境中创建新用户。
问题:我想使用Microsoft PowerShell脚本在sitecore中创建用户。我不想使用sitecore提供的powershell。使用powershell在sitecore中创建用户
我能够在sitecore内使用PowerShell脚本创建用户。但要求是在安装时使用PowerShell脚本在每个环境中创建新用户。
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'[email protected]',
@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 Client Users'是您需要登录到CMS的文件。
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”以最小权限创建用户“启动”。
谢谢你的帮助。 其实我们正在寻找在Windows PowerShell中加载sitecore上下文。 \t 此外,我们不允许直接与sitecore数据库交互 –