Fixing the Operations Manager Shell (PowerShell Interface for SCOM)

 

I go to a lot of customers where when I launch the Operations Manager Shell (PowerShell Interface for SCOM) the shortcut is broken.

image

 

This is often caused by a user installing SCOM to a drive other then the C drive.  I’m sure there a many other possible reasons but lets just focus on fixing it.

First I Open up a new PowerShell Command Prompt as administrator.

Then I run $env:PSModulePath

image

 

Then I run the same command on my SCOM Management Server that I know that the Operations Manager Shell works.

I notice a big difference in the modules listed for my PowerShell environment.

image

I can manually fix the Environment Variable by going to the Advanced System Settings

image

image

**Note you will have to reboot after fixing this as its not the running config**

Just like there is no crying in football there is no GUIs in PowerShell so I wrote this PowerShell script to fix it..

Here is the script I wrote to fix it with comments

#Get the Current Environment Variable PSModulePath Path
$current = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
$current

#Set the Missing Paths  **Note** This may be a different drive or location depending on where you installed SCOM 
$path1 = "C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Powershell\;"
$path2 = "C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Server\PowerShell\;"
$path3 = "C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Powershell\"

#Combine the Missing Paths with the Current PSModulePath Path
$FixedPath = $current + ";" + $path1 + $path2 + $path3
$FixedPath

#Set the new Environment Variable Path for PSModulePath
[Environment]::SetEnvironmentVariable("PSModulePath", $FixedPath, "Machine")

#Set the current running PSModulePath to the stored path  **Note** You can also just reboot
$env:PSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")

Now when I run the shell it works.

image

You can download the script here.  https://www.scom2k7.com/downloads/FixOMShell.txt

2 Responses to Fixing the Operations Manager Shell (PowerShell Interface for SCOM)

  1. Jason July 10, 2017 at 9:37 am #

    This didn’t work, and statement 1 and 3 are the same path? why add it twice, that seems like an install bug

    it’s in my system variables and it still doesn’t load. I can manually run it each time just to “do stuff” and I did install to D drive but would not have if I knew it would be written overseas with bugs.

    .\OperationsManager\Startup.ps1 : The term ‘.\OperationsManager\Startup.ps1’
    is not recognized as the name of a cmdlet, function, script file, or operable
    program. Check the spelling of the name, or if a path was included, verify
    that the path is correct and try again.
    At line:1 char:69
    + Import-Module OperationsManager; .\OperationsManager\Functions.ps1;
    .\Operations …

  2. Jason July 10, 2017 at 9:39 am #

    FYI

    What this guy said to do, did work.

    https://webcache.googleusercontent.com/search?q=cache:lXuxoCK8g9kJ:https://blogs.msdn.microsoft.com/tysonpaul/2017/04/28/scom-operations-manager-shell-powershell-error-when-launched-as-administrator/+&cd=3&hl=en&ct=clnk&gl=us

    run this in elevated PowerShell cmdlet window

    $CMD = ‘$SCOMInstallPath = (Get-ItemProperty -Path “HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup” -Name “InstallDirectory”).InstallDirectory; Set-Location $SCOMInstallPath\..\PowerShell’
    Add-Content -Path $profile.AllUsersAllHosts -Value $CMD -verbose –Force

Leave a Reply