Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mdowst/8978611d371c893c6f4a to your computer and use it in GitHub Desktop.

Select an option

Save mdowst/8978611d371c893c6f4a to your computer and use it in GitHub Desktop.
<#
This script contains the code that was presented in the blog post:
SCSM PowerShell: Getting Started with Service Manager PowerShell
For more details on this and other SCSM PowerShell script see the series overview at http://bit.ly/SCSM-PS
#>
#####################################################################################################
# #
# Load Service Manager PowerShell Modules #
# #
#####################################################################################################
# Service Manager Administrator Module
import-module 'C:\Program Files\Microsoft System Center 2012 R2\Service Manager\Powershell\System.Center.Service.Manager.psd1'
# Service Manager Data Warehouse Module
import-module 'C:\Program Files\Microsoft System Center 2012 R2\Service Manager\Microsoft.EnterpriseManagement.Warehouse.Cmdlets.psd1'
# Service Manager Administrator Module using registry key
$InstallationConfigKey = 'HKLM:\SOFTWARE\Microsoft\System Center\2010\Service Manager\Setup'
$AdminModule = (Get-ItemProperty -Path $InstallationConfigKey -Name InstallDirectory).InstallDirectory + "Powershell\System.Center.Service.Manager.psd1"
Import-Module -Name $AdminModule
# Service Manager Data Warehouse Module using registry key
$InstallationConfigKey = 'HKLM:\SOFTWARE\Microsoft\System Center\2010\Service Manager\Setup'
$DWModule = (Get-ItemProperty -Path $InstallationConfigKey -Name InstallDirectory).InstallDirectory + "Microsoft.EnterpriseManagement.Warehouse.Cmdlets.psd1"
Import-Module -Name $DWModule
# Check if module is loaded
if(@(get-module | where-object {$_.Name -eq 'System.Center.Service.Manager'} ).count -eq 0)
{
$InstallationConfigKey = 'HKLM:\SOFTWARE\Microsoft\System Center\2010\Service Manager\Setup'
$InstallPath = (Get-ItemProperty -Path $InstallationConfigKey -Name InstallDirectory).InstallDirectory + "Powershell\System.Center.Service.Manager.psd1"
Import-Module -Name $InstallPath -Global
}
#####################################################################################################
# #
# Creating PowerShell Profile #
# #
#####################################################################################################
# add command to load Service Manager modules to profile
@'
$InstallationConfigKey = 'HKLM:\SOFTWARE\Microsoft\System Center\2010\Service Manager\Setup'
if(Test-Path $InstallationConfigKey)
{
$AdminModule = (Get-ItemProperty -Path $InstallationConfigKey -Name InstallDirectory).InstallDirectory + "Powershell\System.Center.Service.Manager.psd1"
Import-Module -Name $AdminModule -Global
$DWModule = (Get-ItemProperty -Path $InstallationConfigKey -Name InstallDirectory).InstallDirectory + "Microsoft.EnterpriseManagement.Warehouse.Cmdlets.psd1"
Import-Module -Name $DWModule -Global
}
else
{
throw "ERROR: Could not locate Service Manager PowerShell module on cur"
}
'@ | out-file $profile -Append
#####################################################################################################
# #
# Connecting to Service Manager Management Server #
# #
#####################################################################################################
# Connect to remote management server
New-SCManagementGroupConnection -ComputerName "SCSM01"
# Connect to remote management server using registry key
$ServerConfigKey = 'HKCU:\Software\Microsoft\System Center\2010\Service Manager\Console\User Settings'
$SvcMgmtSrv = (Get-ItemProperty -Path $ServerConfigKey).SDKServiceMachine
New-SCManagementGroupConnection -ComputerName $SvcMgmtSrv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment