SCOM 2012 – Install SCOM PowerShell Modules Without SCOM Console Installation

Yes we all know less is sometimes more. This saying does not only belong to the human bodyweight, nope,  since the Windows Server Core area we all know less “*.dll” is better.

Like this saying, a few days ago I had been asked an interesting question. How can we use the SCOM PowerShell module without installing the entire SCOM console? I thought this is a very good idea and since there are many others which are interested in this scenario I decided to figure it out.

Here is how I did it…

Step 1 – Copy PowerShell Module Source

Copy the Powershell folder from your SCOM management server in c:\Program Files\System Center 2012\Operations Manager\Powershell to your local server where you need the PowerShell modules.

Folders on the management server…

image

and here copied PowerShell folder to the same path as it was on the management server…

image

Step 2 – Add SDK Files

Copy the following three SDK binaries from your management server in C:\Program Files\System Center 2012\Operations Manager\Server\SDK Binaries…

image

to your local GAC (Global Assembly Cache) on your server where you copied the Powershell folder from Step 1.

The Global Assembly Cache is a kind of central store where you can publish your assemblies to the entire system and is located in C:\Windows\Assembly. Now, you just need to drag’n drop the SDK files into the directory and your files will be copied.

image

Note: Should you receive an error that says “Access is denied”, check if UAC is bothering you. There are many sources on the internet about this problem e.g. check this post here .

Step 3 – Set Module Path

Next, we need to set the module path on our server so that the PowerShell console will find the OperationsManager module if we type Import-Module OperationsManager.

Open a PowerShell command window and enter the following three lines…

#Get the current module path
$p = [Environment]::GetEnvironmentVariable(“PSModulePath”)

#Add to the existing path the additional path to our module
$p += “;C:\Program Files\System Center 2012\Operations Manager\Powershell\”

#Set the new path to the PSModulePath variable
[Environment]::SetEnvironmentVariable(“PSModulePath”,$p)

It will look like this…

image

Note: This procedure just sets this path for the current session. If you close the windows the path will be gone and you need to set the path again. If you would like to set the path permanently check TechNet how to do it.

Step 4 – Let’s Import-Module

Run in the same PowerShell window as in step 3 the following command as we are used to anyhow…

Import-Module OperationsManager

image

As you can see, you are able to use the full-featured OperationsManager PowerShell as if the SCOM console were installed. Cool, huh?

I just tested it in my environment, if you hit any problems let me know.

Update 16.03.2013:

As the example above works perfectly, there is one thing you could run into. My colleague Marcel Zehner used this method above and he did some checking on the $Error variable. If you run the procedure above $Error will contain some errors…

image

As we can see the module is searching for additional path like C:\Program Files\System Center 2012\Operations Manager\Server and C:\Program Files\System Center 2012\Operations Manager\Console. In order to solve this problem we just create those two empty directories in these paths…

image

Now if we close the PowerShell window and run the commands again the $Error variable will contain no errors…

image

Thanks to Marcel for telling me about this “problem”.

29 Comments

  1. Hello. This seems like a great idea. I tried this on a test server of mine, and got this error:
    Add-Type : Unable to load one or more of the requested types. Retrieve the Load
    erExceptions property for more information.
    At C:\Program Files\System Center 2012\Operations Manager\Powershell\Operations
    Manager\OperationsManager.psm1:1289 char:15
    + Add-Type <<<< -Path $xPlatDll
    + CategoryInfo : NotSpecified: (:) [Add-Type], ReflectionTypeLoad
    Exception
    + FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Mi
    crosoft.PowerShell.Commands.AddTypeCommand
    Am i missing something? Thanks.

    • Hi

      At this point the script tries to load the Microsoft.SystemCenter.CrossPlatform.ClientLibrary.CredentialManagement.dll. Did you follow the procedure exactly as discribed? I tested this procedure with SCOM 2012 SP1. Did you set the module path as described in step 3?

      Cheers,

      Stefan

  2. Hey

    This is a good solution although its not really a sofisticated way.

    To get the module working from anywhere and anyway. You need to modify the Module Manifest file (“C:\Program Files\System Center 2012\Operations Manager\Powershell\OperationsManager\OperationsManager.psd1”)

    You’ll need replace the “RequiredAssemblies = @()” with

    RequiredAssemblies = @(
    “Microsoft.EnterpriseManagement.Core.dll”,
    “Microsoft.EnterpriseManagement.OperationsManager.dll”,
    “Microsoft.EnterpriseManagement.Runtime.dll”,
    “Microsoft.SystemCenter.OperationsManagerV10.Commands.resources.dll”
    “Microsoft.EnterpriseManagement.Core.Cmdlets.resources.dll”,
    )

    After you done this you need to Copy all of the dll’s to the root folder of the module.
    The additional two dll’s can be found “C:\Program Files\System Center 2012\Operations Manager\Powershell\EN”

    Doing this modification to the Manifest file you’re able to copy “C:\Program Files\System Center 2012\Operations Manager\Powershell\OperationsManager” to anywhere you want.
    Put it on a share and load it with:
    Import-module -path “\\server\share\OperationsManager\OperationsManager.psd1”

    Hope it helped.

    Regard,
    Gabor

    • There were some syntax errors.

      Here are the correction:

      RequiredAssemblies = @(
      “Microsoft.EnterpriseManagement.Core.dll”,
      “Microsoft.EnterpriseManagement.OperationsManager.dll”,
      “Microsoft.EnterpriseManagement.Runtime.dll”,
      “Microsoft.SystemCenter.OperationsManagerV10.Commands.resources.dll”,
      “Microsoft.EnterpriseManagement.Core.Cmdlets.resources.dll”
      )

      To import:
      Import-Module \\server\Share\OperationsManager\OperationsManager.psd1

    • Hi Gabor,

      I tried the steps as you mentioned, however I am getting the following error while importing the module.
      “The assembly “Microsoft.EnterpriseManagement.Core.Dll” was not loaded beacuse no assembly was found”.

      Note: I had copied the dll’s to the root folder of the module.

  3. Gabor,

    I’m pretty new to both powershell and SCOM. I got Stephan method to work properly. I wanted to try your method and what is not clear to me is do I have to copy all the dll. files to the server where I need to use the module?

    In your post you said:
    …Copy all of the dll’s to the root folder of the module? Not sure if you are saying copy the 2 additional dll files from C:\Program Files\System Center 2012\Operations Manager\Powershell\EN to C:\Program Files\System Center 2012\Operations Manager\Server\SDK Binaries or to copy all those to C:\windows\assembly

    Thank you,

  4. Hi Stefan,

    We tried the steps you have mentioned, however we are getting the following error when running New-SCOMAgentgroupconnection.
    “The requestes name is valid, but no data of the requested type was found.”

  5. Hi Stefan,

    I’ve successfully implemented this on a server running Windows Server 2008 R2, putting all the steps into a Powershell script which can be called as part of a scheduled reboot. I’m wondering whether the same steps can be used on Windows Server 2003 as the cmdlets are simply not recognized when I try and execute them. MS state that the cmdlets are supported in Powershell 2.0 but I can find no mention of explicit OS support for them.

    Any thoughts?

      • I am having trouble with your directions, can you help?

        1. Path C:\Program Files\Microsoft System Center 2012 R2\Operations Manager created on computer to run module.

        2. Powershell folder and contents copied to C:\Program Files\Microsoft System Center 2012 R2\Operations Manager from the management server.

        a. I now have C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Powershell\…

        3. Copied the three .DLL files from the SDK Binaries folder from the management server to the computer to run the module. Those file are places in C:\Windows\Assembly

        4. I ran the first three PowerShell commands successfully
        a. $p = [Environment]::GetEnvironmentVariable(“PSModulePath”)
        b. $p += “;C:\Program Files\System Center 2012 R2\Operations Manager\Powershell\”
        i. I used the R2 path
        c. Environment]::SetEnvironmentVariable(“PSModulePath”,$p)

        5. 4th PowerShell Command Fails: Import-Module OperationsManager

        Import-Module : Could not load file or assembly ‘Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral,
        PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
        At C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Powershell\OperationsManager\OperationsManager.psm1:1261
        char:1
        + Import-Module $psScriptRoot\OM10.CoreCommands\OM10.CoreCommands.psd1
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

        Import-Module : Could not load file or assembly ‘Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral,
        PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
        At C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Powershell\OperationsManager\OperationsManager.psm1:1262
        char:1
        + Import-Module $psScriptRoot\OM10.Commands\OM10.Commands.psd1
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

  6. Here is what I did to Import the dlls’ and do what you described above:
    I put my copy of what you described in c:\operations manager directory.
    ____________________________________________________
    cd ‘C:\operationsmanager\Powershell\OperationsManager’

    $dlls = gci -Recurse ‘C:\operationsmanager\Server\SDK Binaries’
    foreach($dll in $dlls)
    {
    Add-Type -Path $dll.FullName

    }
    $env:PSModulePath += ‘C:\operationsmanager\Powershell’;’c:\operationsmanager\server\powershell’
    Import-Module OperationsManager
    .\Startup.ps1
    .\Functions.ps1
    _____________________________________________________

  7. Pingback: OMS Automation Part 2 – Create a Custom Azure Automation Runbook to Execute Against OpsMgr On Premise | Scom Answers

  8. Pingback: SCOM 2012 and Powershell: Quickly get a list of all Distributed Applications | System Center HQ

  9. For the assembly errors: installing the dlls with Gacutil.exe should eliminate these posted workarounds. … well, when policy or UAC prevents installation of the DLLs through explorer, (command line copy doesn’t actually install at all.)

  10. After following the above steps am able to get the SCOM cmdlets. But getting below error. Please help.

    Get-SCOMAlertResolutionState : The Data Access service is either not running or not yet initialized. Check the event log for more information.
    At line:1 char:1
    + Get-SCOMAlertResolutionState
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (Microsoft.Syste…ionStateCommand:GetSCOMAlertResolutionStateCommand) [Get-SCOMAlertResolutionState], ServiceNotRunningException
    + FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.OperationsManagerV10.Commands.GetSCOMAlertResolutionStateCommand

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s