0

I am attempting to gather all of the dbfile information on all of our sql instances in one of our environments. It is a fairly large environment and would be tedious to perform one instance at a time. I thought there would be an easy way to do this with Powershell but I seem to be running into a roadblock.

I have a list of instances stored in a table/view [vSQLInstances]. If I pass those values into a variable and then use that variable as the SQLInstance parameter, I get an error.

Script I'm using...

$sqlinstance = Invoke-DbaQuery -SqlInstance dbasql01\sql2019 -Database DBAEstate -Query "select sqlinstance from vSQLInstance;"

Get-DbadbFile -SqlInstance $sqlinstance | Select-Object sqlinstance, database, logicalname, size 

The error I receive:

Get-DbaDbFile : Cannot process argument transformation on parameter 'SqlInstance'. Cannot convert value 
"@{sqlinstance=PRODSQLD\D}" to type "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter". Error: "Failed to interpret 
input as Instance: @{sqlinstance=PRODSQLD\D}"
At line:11 char:28
+ Get-DbaDbFile -SqlInstance $instancelist
+                            ~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Get-DbaDbFile], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DbaDbFile
3

Yes, that is expected because you are passing in a DataRow type. Instead you could pass it as a string type $sqlinstance.sqlinstance (the column name) as a parameter for Get-DbaDbFile to get the results.

Get-DbaDbFile -SqlInstance $sqlinstance.sqlinstance #...

For example...

malformed command and corrected command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.