Free for PREMIUM members
Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium
Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.
CREATE LOGIN [domain\user]
WITH DEFAULT_DATABASE = [DBName];
-- Add User to first database
CREATE USER [user] FOR LOGIN [domain\user];
EXEC sp_addrolemember '[DbRole]', '[user]'
Open in new window
// reades content of file and sets to $a
$a = Get-Content C:\Scripts\Test.txt
//Split the content with lines....
$a.Split("YourLineSeprator") | ForEach
//$b will be array that contains RemoteServerName,DatabaseName,Ad_GroupName,Role
$os = Get-WmiInfo Win32_OperatingSystem
$conn = New-Object System.Data.SqlClient.SqlConnection
//ConnectionString to Remote Server :: "Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=SSPI;"
//Conn String if you have credentials :: "Data Source=ServerName;Initial Catalog=DatabaseName;uid=username;pwd=password"
$conn.ConnectionString = "Data Source=$b;Initial Catalog=$b;Integrated Security=SSPI;"
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.connection = $conn
//For below line (?) is Username for which you want to set permission..You haven't specified which in your question.
$cmd.commandtext = "CREATE LOGIN $b\(?) FROM WINDOWS WITH DEFAULT_DATABASE = $b;GO USE $b; CREATE USER (?) FOR LOGIN $b\(?); EXEC sp_addrolemember '$b', '(?)'"
Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.