#get_conection.ps1 param( [string] $datasource="10.100.95.166", [string] $database = "Mytest", [string] $authType = "regular", [string] $username ="hydra", [string] $password="hydra123" ) ## Prepare the authentication information. if ($authType -eq "Integrated") { $authentication = "Integrated Security=SSPI;" } else { $authentication = ("uid={0};pwd={1};" -f $username,$password) } # Create the actual connection string $connectionString = "Persist Security Info=True;Initial Catalog=$database;Data Source=$dataSource;$authentication" ## Connect to the data source and open it $connection = new-object System.Data.SqlClient.SqlConnection $connectionString $connection