Configuration Script Troubleshooting

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”.

30 Replies to “SCOM 2012 – Install SCOM PowerShell Modules Without SCOM Console Installation

  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 FilesSystem Center 2012Operations ManagerPowershellOperations
    ManagerOperationsManager.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.

    1. 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 FilesSystem Center 2012Operations ManagerPowershellOperationsManagerOperationsManager.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 FilesSystem Center 2012Operations ManagerPowershellEN”

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

    Hope it helped.

    Regard,
    Gabor

    1. 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 \serverShareOperationsManagerOperationsManager.psd1

    2. 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 FilesSystem Center 2012Operations ManagerPowershellEN to C:Program FilesSystem Center 2012Operations ManagerServerSDK Binaries or to copy all those to C:windowsassembly

    Thank you,

  4. Hey sp_who,

    You’ll need to copy all DLL’s to the OperationsManager (PS Module root folder)

    Regards,
    Gabor

  5. 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.”

  6. 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?

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

        1. Path C:Program FilesMicrosoft System Center 2012 R2Operations Manager created on computer to run module.

        2. Powershell folder and contents copied to C:Program FilesMicrosoft System Center 2012 R2Operations Manager from the management server.

        a. I now have C:Program FilesMicrosoft System Center 2012 R2Operations ManagerPowershell…

        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:WindowsAssembly

        4. I ran the first three PowerShell commands successfully
        a. $p = [Environment]::GetEnvironmentVariable(“PSModulePath”)
        b. $p += “;C:Program FilesSystem Center 2012 R2Operations ManagerPowershell”
        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 FilesMicrosoft System Center 2012 R2Operations ManagerPowershellOperationsManagerOperationsManager.psm1:1261
        char:1
        + Import-Module $psScriptRootOM10.CoreCommandsOM10.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 FilesMicrosoft System Center 2012 R2Operations ManagerPowershellOperationsManagerOperationsManager.psm1:1262
        char:1
        + Import-Module $psScriptRootOM10.CommandsOM10.Commands.psd1
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

  7. 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:operationsmanagerPowershellOperationsManager’

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

    }
    $env:PSModulePath += ‘C:operationsmanagerPowershell’;’c:operationsmanagerserverpowershell’
    Import-Module OperationsManager
    .Startup.ps1
    .Functions.ps1
    _____________________________________________________

  8. 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.)

  9. 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

    1. A little bit late but you have to connect with your SCOM Management Group first:
      New-SCOMManagementGroupConnection -ComputerName “managementservername”

  10. looking for an update for server 2012, seems that the GAC folder structure is different as there is now sub-folders.

  11. Some SCOM cmdlets don’t work in new server. Any idea what might tne the issue?

    Get-SCOMClass -name “Microsoft.SystemCenter.ManagementServer”

    DisplayName Name ManagementPackName Id
    ———– —- —————— —
    Management Server Microsoft.SystemCenter.Mana… Microsoft.SystemCenter.Library 91..

    Get-SCOMAlertResolutionState
    Get-SCOMAlertResolutionState : Exception has been thrown by the target of an invocation.
    At line:1 char:1
    + Get-SCOMAlertResolutionState
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (Microsoft.Syste…ionStateCommand:GetSCOMAlertResolutionStateCommand) [Ge
    t-SCOMAlertResolutionState], TargetInvocationException
    + FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.OperationsManagerV10.Commands.GetSCOMAlertResoluti
    onStateCommand

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.