Quantcast
Viewing all articles
Browse latest Browse all 467

replace string in path using powershell

Hi,i'm trying to get the default sql server data and log file path using the below script...[quote]param($ClientName,$DESTINATIONDB)$SqlConnection = New-Object System.Data.SqlClient.SqlConnection$SqlCmd = New-Object System.Data.SqlClient.SqlCommand$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter$DataSet = New-Object System.Data.DataSet$SqlConnection.ConnectionString = "Server = $ClientName; Database = '$DESTINATIONDB'; Integrated Security = True"$SqlCmd.CommandText = "select f.physical_name from sys.master_files f, sys.databases d where f.database_id = d.database_id and d.name = 'master'" $SqlCmd.Connection = $SqlConnection$SqlAdapter.SelectCommand = $SqlCmd$SqlAdapter.Fill($DataSet)|out-nullforeach ($Row in $Dataset.Tables[0].Rows){ $dev = $($Row[0]) $dev }[/quote]i'm getting the output like thisC:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\master.mdfC:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mastlog.ldfi would like to replace the name of master in the above path my paramter $destinationDB.Please let me knowthanks in advance

Viewing all articles
Browse latest Browse all 467

Trending Articles