31 December 2019

Install Configuration Manager PowerShell Module

I wanted to install the Configuration Manager PowerShell module on my admin machine. After investigating a little, the module does not exist in the Microsoft PowerShell gallery.

The PowerShell script below will create the module directory under the WindowsPowerShell\module directory within %PROGRAMFILES%. It will then copy over all of the necessary files. After copying the files, it will import the module and then verify if the import was successful. Of course, when you want to actually use the module, you will need to connect to the ConfigMgr server using the following cmdlet and then change the site location to the $SiteCode drive:

  • New-PSDrive -Name $SiteCode -PSProvider 'AdminUI.PS.Provider\CMSite' -Root $CMServer -Description $CMSiteDescription | Out-Null
This video shows the script running through the installation and verifying the install:


You will need to locate where the module exists and populate the location in the $ModuleSource parameter. On my ConfigMgr server, it was located at %PROGRAMFILES%\Microsoft Configuration Manager\AdminConsole\bin.

Here is the script below. You can download it from my GitHub site located here


 <#  
      .SYNOPSIS  
           Configuration Manager PowerShell Module  
        
      .DESCRIPTION  
           This will copy the files needed to the computer this script is being executed on. It must be run using an AD account that has priviledges to both the directory on the ConfigMgr server and to the program files directory on the local computer.  
        
      .PARAMETER ModuleSource  
           UNC path containing the Configuration Manager PowerShell module  
        
      .PARAMETER ModuleDirectoryName  
           Name of the directory under the PowerShell Modules directory where the module is copied to  
        
      .NOTES  
           ===========================================================================  
           Created with:     SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.142  
           Created on:       12/27/2019 12:37 PM  
           Created by:       Mick Pletcher  
           Filename:         InstallConfigMgrModule.ps1  
           ===========================================================================  
 #>  
 [CmdletBinding()]  
 param  
 (  
      [ValidateNotNullOrEmpty()]  
      [string]$ModuleSource,  
      [ValidateNotNull()]  
      [ValidateNotNullOrEmpty()]  
      [string]$ModuleDirectoryName = 'ConfigurationManager'  
 )  
   
 #Location where to copy the module to  
 $ModuleDestination = $env:ProgramFiles + '\WindowsPowerShell\Modules\' + $ModuleDirectoryName  
 #Remove the module from memory if it has already been imported  
 Remove-Module -Name ConfigurationManager -Force -ErrorAction SilentlyContinue  
 #Remove ConfigurationManager directory if it already exists  
 Remove-item -Path $ModuleDestination -Recurse -Force  
 #Create the directories for the PowerShell module  
 New-Item -Path $ModuleDestination -ItemType Directory -Force | Out-Null  
 New-Item -Path ($ModuleDestination + '\en-US') -ItemType Directory -Force | Out-Null  
 #Copy all necessary files for the Configuration Manager PowerShell Module  
 Get-ChildItem -Path $ModuleSource -Filter 'adminui.ps.*' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'adminui.wqlqueryengine.dll' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'Microsoft.ConfigurationManagement.*' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter '*.ps1xml' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'AdminUI.*' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'ConfigurationManager.psd1' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'Dcm*' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'Microsoft.Diagnostics.*' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'Microsoft.ConfigurationManagement.*' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Get-ChildItem -Path $ModuleSource -Filter 'Microsoft.ConfigurationManager.*' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination $ModuleDestination; If ((Test-Path ($ModuleDestination + '\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 #Copy all help files to the module folder  
 Get-ChildItem -Path ($ModuleSource + '\en-US') -Filter '*.xml' | ForEach-Object {Write-Host ('Copying ' + $_.Name + '.....') -NoNewline; Copy-Item -Path $_.FullName -Destination ($ModuleDestination + '\en-US'); If ((Test-Path ($ModuleDestination + '\en-US\' + $_.Name)) -eq $true) {Write-Host 'Success' -ForegroundColor Yellow} else {Write-Host 'Failed' -ForegroundColor Red}}  
 Import-Module -Name $ModuleDirectoryName  
 Write-Host  
 If (Get-Module -ListAvailable -Name $ModuleDirectoryName) {  
      Remove-Module -Name $ModuleDirectoryName -Force  
      Write-Host ($ModuleDirectoryName + [char]32 + 'PowerShell module installed successfully') -ForegroundColor Yellow  
 } else {  
      Write-Host ($ModuleDirectoryName + [char]32 + 'PowerShell module installation failed') -ForegroundColor Red  
 }  
   

Related Posts:

  • Configure PowerShell Settings Recently, we needed to start building select machines off of our domain for special projects. This meant that group policies would not be applied. I use GPOs to set PowerShell settings on all of the machines. With these mac… Read More
  • Install Dell Command Update and Flash BIOS in WinPE I have wanted to get the process of flashing the BIOS into the WinPE environment for quite a while. With the help of Sapien's PowerShell Studio, I finally wrote the script to make this possible. The purpose is that it can f… Read More
  • Initiating SCCM Actions with Verification The latest script I am writing requires me to initiate both a software updates scan cycle and a software updates deployment evaluation cycle before continuing with the script. The actions needed to be completed before the s… Read More
  • NIC Advanced Properties Recently, we started having issues with our new Dell Latitude E7450 laptops. They would be put to sleep and then they could not restore the network connection once the laptop was docked again. The problem came from the Ener… Read More
  • PowerShell: Set Windows Features with Verification I am in the beginning stages of creating a Windows 10 build. One of the first things I needed to do was to install and set the Windows 10 features. Before, I used a batch script that executed DISM to set each feature. I kno… Read More

0 comments:

Post a Comment