Thursday 22 August 2013

Make SCOM 2012 PS Module Portable

A few days back I was thinking that in SCOM 2012 Microsoft has converted the SCOM 07 PowerShell Snap-in to a Module. So I was wondering if we could put this module in a Module repository, and we could access it from a central location without any installation.

I started searching a way to separate the SCOM PS module from the SCOM Console installation. I came across a blog entry. Where the blogger's main idea was to copy the Module to the new server to the same path and copy the binaries to C:\Windows\Assembly. Although this is good solution it's just not scalable.

So I decided that I want a portable module that could be loaded from a network share without any problem or dll copying.

I remembered that the Module Manifest (psd1) file has an option Requiredassemblies.
So after some research I found the solution. What we need to do is we copy the dll's to the root folder of the module and add them to the Manifest file. It's easy isn't it?

So lets see the steps:

We'll need a server where the Operations Manager 2012 Console is installed. We'll be able to find the module under this path: "C:\Program Files\System Center 2012\Operations Manager\Powershell\OperationsManager"

We can copy the OperationsManager folder to somewhere i.e.: C:\PSModules\OperationsManager

After this is done We need the following Dll's to be copied to the root folder of the module.

From the following folder: "C:\Program Files\System Center 2012\Operations Manager\Server\SDK Binaries" 
We need these three dll's: 
 Microsoft.EnterpriseManagement.Core.dll
 Microsoft.EnterpriseManagement.OperationsManager.dll
 Microsoft.EnterpriseManagement.Runtime.dll

We also need some resource dll's which hold information about the cmdlets. 
These are located in the following folder: "C:\Program Files\System Center 2012\Operations Manager\Powershell\EN\"
The file names are: 
Microsoft.EnterpriseManagement.Core.Cmdlets.resources.dll, 
Microsoft.SystemCenter.OperationsManagerV10.Commands.resources.dll

After this is done. One more thing need to be done and we're ready.

We need to tell PS which dll's we want to load before the module. We can do that by simply add the file names to the Module Manifest file.

So lets do it. Edit the manifest file "C:\PSModules\OperationsManager\OperationsManager.psd1"
Search for the following section:
 # A list of assemblies that must be loaded before this module can work.  
 RequiredAssemblies = @()  
And add the dll names as per below example:
 # A list of assemblies that must be loaded before this module can work.  
 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 this is done. We're done. :)

To import it we only need to do is the following:
 Import-Module \\server\share\OperationsManager\OperationsManager.psd1  

So now we have a portable Operations Manager 2012 module which we can put to file share or anywhere. If you have a PS script which is managing SCOM you can run it from everywhere you'll just need to load the module in the beginning of the script.

Hope this was useful,
Stholo