Add-Member does not work on SMO Database object when created from the Databases collection. - by Kyle Neier

Status : 


Sign in
to vote
ID 751396 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 6/28/2012 1:02:15 PM
Access Restriction Public


I'm not certain whether this belongs in Powershell or SQL Server, but since using the types.ps1xml files makes this work properly, I assume it's a problem with Add-Member and not SMO.

Whenever instantiating a new Microsoft.SqlServer.Management.SMO.Database object by indexing into a Microsoft.SqlServer.Management.Smo.Server Databases collection, add-member will not persist the added property for use. 

If you supply the -PassThru parameter, you can use the property in the pipeline, but the property is still absent from the object after adding it.

If you use the New-Object command to create the database object, Add-Member works fine. If you call the .Name property of the object prior to using Add-Member, it works fine as well. 

I've tried this with various MemberType values and it seems that the type of member you are trying to add is irrelevant.

The first and third sections of repro work as expected. The second does not - it returns nothing to the console nor does a get-member show the new property that was just added.
Sign in to post a comment.