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
asked Sep 27, 2020 at 22:44

1 Answer 1

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

Peter Vandivier
5,8301 gold badge25 silver badges50 bronze badges
answered Sep 28, 2020 at 6:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.