11# Author: Blake Drumm ([email protected] )22# Date created: February 29th, 2024
3+ # Date modified: March 20th, 2024
34# Description: This script will allow you to make the System Center Operations Manager PowerShell module portable.
45# Run this on a server that is a SCOM Management Server or has the Console installed on it. The script will
56# zip up the output folder and all you have to do is copy the zip to a remote machine (where you want to install
@@ -15,9 +16,13 @@ $zipFilePath = "C:\Temp\SCOM-PowerShellModule.zip"
1516
1617# The path to the Powershell folder in the SCOM installation folder
1718$powerShellFolder = Get-ItemPropertyValue - Path " HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2" - Name InstallDirectory
19+ $serverFolder = Get-ItemPropertyValue - Path " HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Server" - Name InstallDirectory
20+ $consoleFolder = Get-ItemPropertyValue - Path " HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Console" - Name InstallDirectory
1821# Uncomment the below to force the path to a specific directory, instead of detecting automatically from the registry.
1922# $powerShellFolder = "C:\Program Files\Microsoft System Center\Operations Manager\Powershell"
2023Write-Output " PowerShell folder path: $powerShellFolder "
24+ Write-Output " Server folder path: $serverFolder "
25+ Write-Output " Console folder path: $consoleFolder "
2126
2227# Check if the folder exists
2328if (-Not (Test-Path - Path $folderPath ))
3237 Write-Output " Output folder '$folderPath ' already exists."
3338}
3439
40+ if (-Not (Test-Path - Path $folderPath \Server))
41+ {
42+ # Folder does not exist, so create it
43+ New-Item - ItemType Directory - Path $folderPath \Server - Force | Out-Null
44+ Write-Output " Output folder '$folderPath \Server' has been created."
45+
46+ $langCodes = @ (
47+ ' cs' ,
48+ ' de' ,
49+ ' en' ,
50+ ' es' ,
51+ ' FR' ,
52+ ' HU' ,
53+ ' IT' ,
54+ ' JA' ,
55+ ' KO' ,
56+ ' NL' ,
57+ ' PL' ,
58+ ' pt-BR' ,
59+ ' pt-PT' ,
60+ ' RU' ,
61+ ' SV' ,
62+ ' TR' ,
63+ ' zh-CHS' ,
64+ ' zh-CHT' ,
65+ ' zh-HK'
66+ )
67+
68+ $langCodes | ForEach-Object { New-Item - ItemType Directory - Path $folderPath \Server\$_ - Force | Out-Null }
69+ }
70+ else
71+ {
72+ # Folder already exists
73+ Write-Output " Output folder '$folderPath \Server' already exists."
74+ }
75+
76+ if (-Not (Test-Path - Path $folderPath \Console))
77+ {
78+ # Folder does not exist, so create it
79+ New-Item - ItemType Directory - Path $folderPath \Console - Force | Out-Null
80+ Write-Output " Output folder '$folderPath \Console' has been created."
81+ }
82+ else
83+ {
84+ # Folder already exists
85+ Write-Output " Output folder '$folderPath \Console' already exists."
86+ }
87+
3588Get-ChildItem ' C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.EnterpriseManagement*' | ForEach-Object {
3689 Copy-Item - Path $_.FullName - Destination $folderPath - Force - Recurse
3790}
3891
3992Write-Output " - Copied the required GAC_MSIL files."
4093
94+ # PowerShell Folder Path
4195try
4296{
4397 $resolvedPath = (Resolve-Path - Path $powerShellFolder - ErrorAction Stop).Path
@@ -49,9 +103,43 @@ catch
49103 break
50104}
51105
106+ # Server Folder Path
107+ try
108+ {
109+ $resolvedPath = (Resolve-Path - Path $serverFolder - ErrorAction Stop).Path
110+ Copy-Item - Path " $resolvedPath \Microsoft.Mom.Common.dll" - Destination $folderPath \Server - Force
111+ Copy-Item - Path " $resolvedPath \Microsoft.EnterpriseManagement.DataAccessLayer.dll" - Destination $folderPath \Server - Force
112+ Copy-Item - Path " $resolvedPath \Microsoft.EnterpriseManagement.DataAccessService.Core.dll" - Destination $folderPath \Server - Force
113+ Copy-Item - Path " $resolvedPath \Microsoft.Mom.Sdk.Authorization.dll" - Destination $folderPath \Server - Force
114+ $langCodes | ForEach-Object { Copy-Item - Path " $resolvedPath \$_ " - Destination $folderPath \Server - Force }
115+ Write-Output " - Copied the required Management Server DLL files."
116+ }
117+ catch
118+ {
119+ Write-Warning " Unable to locate the path '$serverFolder '!"
120+ break
121+ }
122+
123+ # Console Folder Path
124+ try
125+ {
126+ $resolvedPath = (Resolve-Path - Path $consoleFolder - ErrorAction Stop).Path
127+ Copy-Item - Path $resolvedPath \Microsoft.Mom.Common.dll - Destination $folderPath \Console - Recurse - Force
128+ Write-Output " - Copied the required Operations Manager Console DLL files."
129+ }
130+ catch
131+ {
132+ Write-Warning " Unable to locate the path '$consoleFolder '!"
133+ break
134+ }
135+
52136# Create a text file with the $powerShellFolder path inside the $folderPath
53137Set-Content - Path " $folderPath \PowerShellFolderInfo.txt" - Value " $powerShellFolder "
54138
139+ Set-Content - Path " $folderPath \ServerFolderInfo.txt" - Value " $serverFolder "
140+
141+ Set-Content - Path " $folderPath \ConsoleFolderInfo.txt" - Value " $consoleFolder "
142+
55143Set-Content - Path " $folderPath \Install-SCOMModule.ps1" - Value @"
56144[CmdletBinding()]
57145param ()
101189
102190
103191`$ powerShellFolder = Get-Content .\PowerShellFolderInfo.txt
192+ `$ serverFolder = Get-Content .\ServerFolderInfo.txt
193+ `$ consoleFolder = Get-Content .\ConsoleFolderInfo.txt
194+
104195try
105196{
106197 `$ gacPath = (Resolve-Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL" -ErrorAction Stop).Path
@@ -111,25 +202,30 @@ catch
111202 return
112203}
113204Get-ChildItem ".\Microsoft.EnterpriseManagement*" | % {
114- `$ resolvePath = Resolve-Path `$ gacPath\`$ (`$ _.Name)
205+ `$ resolvePath = Resolve-Path `$ gacPath\`$ (`$ _.Name) -ErrorAction SilentlyContinue
115206 if (-NOT `$ resolvePath)
116207 {
117208 Copy-Item -Path `$ _.FullName -Destination `$ gacPath -Force -Recurse
118209 }
119210}
120211Copy-Item -Path .\Powershell\ -Destination `$ powerShellFolder -Force -Recurse
121212
213+ Copy-Item -Path .\Server\ -Destination `$ serverFolder -Force -Recurse
214+
215+ Copy-Item -Path .\Console\ -Destination `$ consoleFolder -Force -Recurse
216+
122217`$ p = [Environment]::GetEnvironmentVariable("PSModulePath")
123- if (-NOT `$ p -contains `$ powerShellFolder)
218+ if (`$ p -notcontains `$ powerShellFolder)
124219{
125- `$ p += ";`$ powerShellFolder"
126- [Environment]::SetEnvironmentVariable("PSModulePath", `$ p , 'Machine')
220+ `$ envVariable += "`$ p ;`$ powerShellFolder"
221+ [Environment]::SetEnvironmentVariable("PSModulePath", `$ envVariable , 'Machine')
127222 Write-Output " - Added module to the machine level environmental variable (PSModulePath)"
128223}
129224else
130225{
131226 Write-Output " - Module is already in the machine level environmental variable (PSModulePath)"
132227}
228+ <#
133229try
134230{
135231 Import-Module OperationsManager -Verbose -ErrorAction Stop
@@ -139,7 +235,9 @@ catch
139235 Write-Warning "Unable to import the SCOM PowerShell Module!`n`$ _"
140236 return
141237}
142- Write-Output "Completed importing the SCOM PowerShell Module!
238+ Write-Output "Completed importing the SCOM PowerShell Module!"
239+ #>
240+ Write-Output "Close this window and reopen a new PowerShell window. Run the following command to import the Operations Manager PowerShell module: Import-Module OperationsManager"
143241"@
144242
145243Set-Content - Path " $folderPath \Readme.txt" - Value @"
0 commit comments