The following powershell script works fine....
foreach ($svr in get-content "C:\AllServers.txt")
{
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$serverinstance = new-object ('Microsoft.SqlServer.Management.Smo.Server') $svr
foreach ($db in $serverinstance.databases)
{
$fgs = $db.Filegroups
foreach ($fg in $fgs)
{
$files = $fg.files
$serverinstance.name + '|' `
+ $db.name + '|' `
+ $fg.name + '|' `
+ $fg.Filename + '|' `
+ $fg.size | out-file "C:\DBFiles.txt" -append
}
}
}
EXCEPT, the $fg.Filename will not output the .mdf filepath. It is empty.
When I change the script to.....
foreach ($svr in get-content "C:\AllServers.txt")
{
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$serverinstance = new-object ('Microsoft.SqlServer.Management.Smo.Server') $svr
foreach ($db in $serverinstance.databases)
{
$fgs = $db.Filegroups
foreach ($fg in $fgs)
{
$files = $fg.files
$files | select $db.name, Name, Filename, Size | out-file "C:\DBFiles.txt" -append
}
}
}
...it returns the file path perfectly.
Can someone please point me in the right direction? I need the above information output into a pipe delimited text file.
ugh....
Thanks yall!
foreach ($svr in get-content "C:\AllServers.txt")
{
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$serverinstance = new-object ('Microsoft.SqlServer.Management.Smo.Server') $svr
foreach ($db in $serverinstance.databases)
{
$fgs = $db.Filegroups
foreach ($fg in $fgs)
{
$files = $fg.files
$serverinstance.name + '|' `
+ $db.name + '|' `
+ $fg.name + '|' `
+ $fg.Filename + '|' `
+ $fg.size | out-file "C:\DBFiles.txt" -append
}
}
}
EXCEPT, the $fg.Filename will not output the .mdf filepath. It is empty.
When I change the script to.....
foreach ($svr in get-content "C:\AllServers.txt")
{
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$serverinstance = new-object ('Microsoft.SqlServer.Management.Smo.Server') $svr
foreach ($db in $serverinstance.databases)
{
$fgs = $db.Filegroups
foreach ($fg in $fgs)
{
$files = $fg.files
$files | select $db.name, Name, Filename, Size | out-file "C:\DBFiles.txt" -append
}
}
}
...it returns the file path perfectly.
Can someone please point me in the right direction? I need the above information output into a pipe delimited text file.
ugh....
Thanks yall!