Hello,
Sorry for the (very) late response I have been away. I have gone down a different road and I am currently stuck with this at the moment:
[String] $inventoryinstance="Server\Instance"
[String] $inventorydatabase="Database"
$smoAssembly = [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
if (!($smoVersion))
{ Set-Variable -name SmoVersion -value $smoAssembly.GetName().Version.Major -Scope Global -Option Constant
-Description "SQLPSX variable" }
[reflection.assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended') > $null
#Get-DataFilePath
function Get-DataFilePathList
{
$instance = New-Object ('Microsoft.SQLServer.Management.SMO.Server') $inventoryinstance
$database = $instance.Databases[$inventorydatabase]
#Param ($database)
$result=$database.ExecuteWithResults("SELECT InstanceName, DBName, DataFilePath from
dbo.tblDatabases")
$result.Tables | foreach {$_.Rows}
}
Get-DataFilePathList | foreach {$_.DataFilePath | Write-Output}
The output from this is the data file directories:
D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\master.mdf
D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\tempdb.mdf
D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\model.mdf
D:\MSSQL10.DEV806MSSQL\MSSQL\DATA\MSDBData.mdf
D:\MSSQL10.DEV806MSSQL\MSSQL\Data\DBA_Maint.mdf
What's the best way to feed the output from this; $_.DataFilePath into a Foreach loop to get the permissions. (cacls/Get-Acl)
Thanks in advance for the response.