USE [CFG]
GO
/****** Object:  StoredProcedure [dbo].[ncspCreateUserWrap]    Script Date: 05.01.2015 9:25:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[ncspCreateUserWrap](
	@tmpNewUsertbl nvarchar(128)
) as

begin

	/* CFG */
	set nocount on;
	declare @ErrorMessage nvarchar(4000), @ErrorSeverity int, @ErrorState int, @scriptPath varchar(260);
	begin try

		--select @scriptPath = 'powershell.exe -file ' + path  + 'addUser.ps1 -' + @tmpNewUsertbl from cfg.dbo.ncvGetRootPath where Id = 35;
		--select @scriptPath = 'powershell.exe -file ' + 'C:\Temp\'  + 'addUser.ps1 -' + @tmpNewUsertbl --from cfg.dbo.ncvGetRootPath where Id = 35
		--exec dbo.ncspCreateUserWrapExec @tmpNewUsertbl
		--exec xp_cmdshell @scriptPath, no_output;
		exec cfg.dbo.ncspCreateUserCLR @tmpNewUsertbl;

	end try
	begin catch
		set @ErrorMessage = error_message();
		set @ErrorSeverity = error_severity();
		set @ErrorState = error_state();

		raiserror(@ErrorMessage, @ErrorSeverity, @ErrorState);
	end catch
end