Tuesday, 27 August 2013

Who I am


So because last time I've only created a quick post about my finding. Now I'm going to post a short description about my self and my blog.


I'm a IT Operations person in at a large firm. I work as a Windows Server Operations L3 person with some Unix background. I'm an enthusiastic scripter and a big fan of automatisation. If you can save time by writing a script, than why not, right? In a large environment there is no other option any way.
During my day to day job I look over a quite big SCOM Infra and of course a big number of Windows Servers. Because of this I'm heavily relying on powershell and scripting in general.

The purpose of this blog is mainly to share my findings and solutions. When I usually face a problem and I'm able to solve it. It's a great pleasure.. so why shouldn't I shout it out loud? Maybe somebody else will find it use full. A perfect example is my first post. I was looking for a way to make the SCOM 2012 PS module portable to make it scale and finally the post was born. :)

Hopefully I'm going to be able to post new things as I face them and it's going to be use full.

Stholo

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