param(
	[string]$hostname,
	[string]$database,
	[string]$login,
	[string]$password
 )

$connectionStringBuilder = New-Object -TypeName System.Data.SqlClient.SqlConnectionStringBuilder
$connectionStringBuilder.Add('Server', $hostname)
$connectionStringBuilder.Add('Database', $database)
$connectionStringBuilder.Add('UID', $login)
$connectionStringBuilder.Add('PWD', $password)
$connectionStringBuilder.Add('Connection Timeout','30')

$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionStringBuilder.ToString()

$command = $connection.CreateCommand()
$command.CommandText = "EXEC sp_spaceused" 
$adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command
$dataset = New-Object -TypeName System.Data.DataSet
$adapter.Fill($dataset) > null

foreach ($table in $dataset.Tables) {
	foreach ($row in $table.Rows) {
		foreach ($col in $table.Columns) {
			Write-Host $col.ColumnName $row[$col]
		}
	}
}

$command = $connection.CreateCommand()
$command.CommandText = "SELECT name, physical_name FROM sys.master_files"
$adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command
$dataset = New-Object -TypeName System.Data.DataSet
$adapter.Fill($dataset) > null
foreach ($table in $dataset.Tables) {
	foreach ($row in $table.Rows) {
		if ($row["name"] -eq $database) {
			Write-Host "db_file_location" $row["physical_name"]
		}
	}
}
