SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


problem with EnumObjects in powershell/SMO script


problem with EnumObjects in powershell/SMO script

Author
Message
Rob 8503
Rob 8503
SSC-Enthusiastic
SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)

Group: General Forum Members
Points: 144 Visits: 21
I have a code like this

$objectTypeFlags = [long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::All -bxor (
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::Certificate +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]:BigGrinatabaseRole +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::ExtendedStoredProcedure +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::MessageType +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::ServiceBroker +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::ServiceContract +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::ServiceQueue +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::ServiceRoute +
[long][Microsoft.SqlServer.Management.Smo.DatabaseObjectTypes]::SqlAssembly)

#and we store them in a datatable
$d = New-Object ("System.Data.DataTable")

#get everything except the information schema, system views, and some other extra items


$objectTypeFlags
#Break



$d = $db.EnumObjects($objectTypeFlags) |
Where-Object {
$_.Schema -ne "sys" -and
$_.Name -ne "sys" -and
$_.Schema -ne "information_schema" -and
$_.Name -ne "information_schema" -and
$_.Schema -notlike "db_*" -and
$_.Name -notlike "db_*" -and
$_.Name -notlike "sp_*diagram*" -and
$_.Name -ne "fn_diagramobjects" -and
$_.Name -ne "sysdiagrams" -and
$_.Schema -ne "guest" -and
$_.Name -ne "guest" }


that gives me this error:


Exception calling "EnumObjects" with "1" argument(s): "Enum objects failed for Database 'UDW_DATA_DICTIONARY'. "
At C:\scripts\GenerateSqlScripts.ps1:156 char:1
+ $d = $db.EnumObjects($objectTypeFlags) |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Smile [], MethodInvocationException
+ FullyQualifiedErrorId : FailedOperationException



the variable $objectTypeFlags=35184237809365
line 156 where the error occurs is
$d = $db.EnumObjects($objectTypeFlags) |



also find attached the entire script that i run like this

.\GenerateSqlScripts.ps1 udwsqldev02.usask.ca UDW_DATA_DICTIONARY C:\scripts\udwsqldev02\udw_data_dictionary
ssaari 68644
ssaari 68644
SSC Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 Visits: 43
May I please ask, did this ever run successfully? Dumb question: Are you running as a user that has rights to all database objects?
I would comment out all but one or two flags and uncomment one at a time to reveal what exactly breaks. It might help to add $_.name to the output to see what's executing.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search