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


Got a newbie SMO powershell question/issue.


Got a newbie SMO powershell question/issue.

Author
Message
Duran
Duran
SSCertifiable
SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)

Group: General Forum Members
Points: 7976 Visits: 1901
Hello everyone,

I'm quite new to PowerShell, but getting along OK with a PS cookbook, but I have run into an issue and I cant get around it, and looking for some help.

I just wanted to list the service accounts, it all looks good but I am getting the following error when I run it which I am fairly sure relates to $managedcomputer.services

PS SQLSERVER:\> $managedComputer.Services
The following exception occurred while trying to enumerate the collection: "SQL Server WMI provider is not available on MyNamed\instance.".
At line:1 char:1
+ $managedComputer.Services
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Smile [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : ExceptionInGetEnumerator

I did import the module SQLPS, and their are no problems with that. My actual code is...

#import SQL Server Module
Import-Module SQLPS -DisableNameChecking
$InstanceName = "MYNAMED\INSTANCE"
$managedComputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $InstanceName
#ListServices
$managedComputer.Services |
Select Name, ServiceAccount, DisplayName, ServiceState | Format-Table -AutoSize

So I downloaded the SQL 2012 Feature Pack to get the SQLSysClrTypes, SharedManagementObjects, and PowerShellTools, which google led me to from the error I was receiving, and now face an additional issue whereby I cannot install the sharedmanagment objects because it says I need to install the SQLSysCLRTypes as a prerequisite, buts already installed. I also tried uninstalling, and also tried the 32 bit options.

I'm enjoying learning PS, but this is just a pain. I am running it within the ISE in case its important.

Any advice? PowerShell V3 BTW.

Thank you.

Regards,
D.
Duran
Duran
SSCertifiable
SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)

Group: General Forum Members
Points: 7976 Visits: 1901
This may obvious to most, but I worked this out in the end, I had to register the assemblies, for anyone else that may come across this, you install the SDK off the SQL Server media and then navigate to the SDK folder and find your assemblies (.dll) and register them in PowerShell

Example: (you path may be different, I just registered everything I thought I might need)

Add-Type -Path 'C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.sqlEnum.dll'
Add-Type -Path 'C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.wmiEnum.dll'
Add-Type -Path 'C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServerEnum.dll'

Add-Type -Path 'C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SmoExtended.dll'

Add-Type -Path 'C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll'

Add-Type -Path 'C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SqlWmiManagement.dll'

How to register SQL server assemblies in PowerShell

Regards,
D
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