To use SMO with PowerShell, first you need to load the assembly
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SqlWmiManagement') | Out-Null
$s = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer PABLITO $s ConnectionSettings : Microsoft.SqlServer.Management.Smo.Wmi.WmiConnectionInfo Services : ClientProtocols : ServerInstances : ServerAliases : Urn : ManagedComputer[@Name='PABLITO'] Name : PABLITO Properties : {} UserData : State : Existing
$s.Services The following exception occurred while trying to enumerate the collection: "An exception occurred in SMO while trying to manage a service.". At line:1 char:1 + $s.Services + ~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException + FullyQualifiedErrorId : ExceptionInGetEnumerator
Get-ChildItem "c:\program files (x86)\Microsoft SQL Server\*\Shared\sqlmgmproviderxpsp2up.mof" | Sort-Object CreationTime | Select-Object Directory Directory --------- C:\program files (x86)\Microsoft SQL Server\90\Shared C:\program files (x86)\Microsoft SQL Server\100\Shared C:\program files (x86)\Microsoft SQL Server\110\Shared
$i = Get-ChildItem "c:\program files (x86)\Microsoft SQL Server\*\Shared\sqlmgmproviderxpsp2up.mof" | Sort-Object CreationTime | Select-Object Directory -Last 1 mofcomp "$($i.Directory)\sqlmgmproviderxpsp2up.mof" Microsoft (R) MOF Compiler Version 6.1.7600.16385 Copyright (c) Microsoft Corp. 1997-2006. All rights reserved. Parsing MOF file: C:\program files (x86)\Microsoft SQL Server\110\Shared\sqlmgmproviderxpsp2up.mof MOF file has been successfully parsed Storing data in the repository... Done!
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SqlWmiManagement') | Out-Null $s = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer PABLITO $s.Services