I’m please to announce the release of my first PowerShell module named CM2012 version 0.1 for ConfigMgr 2012. I started working on this PowerShell module a while back when I realized I started to get a bunch of scripts that I used from time to time. In addition to that, my colleague Stefan Schörling who wrote this great blog post a while back had me inspired for most of the functions that ended up in this module. So, why not put them all together into one single module and have it loaded when I start the PowerShell console?

I must point out that this is the first release and there might be bugs. So if you decide to give it a try and run into any problems, please do not hesitate to contact me and I’ll help you out. Any suggestions to how the module can be extended with more functionality are highly appreciated, so please let me know.

Overview

  • Download the CM2012 module
  • Import the module
  • Functions embedded in the module
  • Getting information about functions
  • Documentation

Download the CM2012 module

I’ve uploaded the module to the TechNet Gallery and it’s available here.

Import the module

Once you’ve downloaded the zip-file containg the module, extract it to this location:

C:\Users\<username>\Documents\WindowsPowerShell\Modules\CM2012

If you do not have the WindowsPowerShell folder in the Documents folder, no worries, just create it and then create another folder named Modules and then CM2012. See the picture below.

78_1

Open a PowerShell console and type the following:

Import-Module CM2012

Once the module has been imported, you can run the following command to verify that it was indeed imported:

Get-Module CM2012

78_2

Now that the module is imported, let’s continue to explore what’s available to us.

Functions available in the module

In the first release of this module, there are a number of 12 functions available. I’ll go into more detail about each of them and how they can be used in the Documentation section further along in this post. But here’s an overview of the functions available:

  • Get-SQLInstanceMemory
  • Get-IISLogLocation
  • Get-PXECacheExpire
  • New-NoSMSOnDrive
  • New-SkipSoftwareInventory
  • Remove-IISLogs
  • Rename-CMCollectionNames
  • Rename-CMFolderNames
  • Set-IISLogLocation
  • Set-MaxMIFSize
  • Set-PXECacheExpire
  • Set-SQLInstanceMemory

If you’d like to see what’s available from the console, run the following command:

Get-Command -Module CM2012

78_3_2

Getting information about functions

All of the functions, or also referred to as cmdlets, in the module contains information on how they can be used. In order to get more information on any of the functions, you can run the following command:

Get-Help New-NoSMSOnDrive -Full

78_4

Documentation

From now on I will refer to the available functions as cmdlets, just because it seems more appropriate. Most of the cmdlets needs to be executed elevated in order to function properly. If you get unexpected results from the cmdlets, always try to elevate with administrative permissions.

Get-SQLInstanceMemory
This cmdlet will retrieve the Maximum and Minimum values from the memory configuration of a SQL Instance. It has to be run against a local SQL Server, and it requires the Microsoft.SqlServer.Smo assembly.

Example command:

Get-SQLInstanceMemory -Instance "."

78_5

Set-SQLInstanceMemory
This cmdlet will configure the memory configuration of a SQL Instance with the specified Maximum and Minimum values. It has to be run against a local SQL Server, and it requires the Microsoft.SqlServer.Smo assembly.

Example command:

Set-SQLInstanceMemory -InstanceName "." -MinMemory 0 -MaxMemory 2048

78_6

New-NoSMSOnDrive
This cmdlet will create an empty file called NO_SMS_ON_DRIVE.SMS in the specified drive root. This file is used to declare that the specified drive should not contain any files associated with ConfigMgr. This cmdlet does not produce any output.

Example command:

New-NoSMSOnDrive -Drive C:

78_7

New-SkipSoftwareInventory
This cmdlet will create an empty file called skpswi.dat in the specified path. This file is used to declare to ConfigMgr that there should be no Software Inventory from a folder structure and recursively. This cmdlets does not produce any output.

Example command:

New-SkipSoftwareInventory -Path C:\

78_8

Get-IISLogLocation
This cmdlet will get the current location of the IIS log file configuration. It can be executed on a remote system by specifying a value for the ComputerName parameter. This cmdlet does not produce any output.

Example command:

Get-IISLogLocation -ComputerName CM01

78_10

Set-IISLogLocation
This cmdlet will set the location of the IIS log file configuration to a specified path. If the specified path doesn’t exist, it’s created automatically. It can be executed on a remote system by specifying a value for the ComputerName parameter. This cmdlet does not produce any output.

Example command:

Set-IISLogLocation -ComputerName CM01 -Path C:\IIS\Logs

78_9

Remove-IISLogs
This cmdlet will remove IIS log files older than a certain amount of days. The amount of days to keep is specified with the Age parameter. If the SiteName parameter is not used, it will execute for all IIS Sites. This cmdlet can be executed on a remote system by specifying a value for the ComputerName parameter. This cmdlet outputs a PSObject.

Example command:

Remove-IISLogs -ComputerName CM01 -Age 7 -SiteName 'Default Web Site'

78_11

Rename-CMCollectionNames
This cmdlet will rename all collections that has a particular value in it’s name. The value that will be located in the collection name is specified with the Locate parameter, and what’s being replaced is specified with the Replace parameter. In order to control which type of collection the cmdlet will rename, use the CollectionType parameter and specify an integral value. This cmdlet can be executed on a remote system by specifying a value for the ComputerName parameter. This cmdlet outputs a PSCustomObject for each collection that has been updated.

CollectionType values:

0 = Other
1 = User collection
2 = Device collection

Example command:

Rename-CMCollectionNames -ComputerName CM01 -CollectionType 2 -Locate PS1 -Replace PS2

78_12

Rename-CMFolderNames
This cmdlet will rename all folders that has a particular value in it’s name. The value that will be located in the collection name is specified with the Locate parameter, and what’s being replaced is specified with the Replace parameter. In order to control which type of folder the cmdlet will rename, use the ObjectType parameter and specify an integral value. This cmdlet can be executed on a remote system by specifying a value for the ComputerName parameter. This cmdlet outputs a PSCustomObject for each collection that has been updated.

ObjectType values:

2 = Packages Node
8 = Reports Node
9 = Software Metering Node
14 = OS Installers Node
16 = Virtual Hard Disks Node
17 = User Collections Node
18 = OS Images Node
19 = Boot Images Node
20 = Task Sequences Node
23 = Driver Packages Node
25 = Drivers Node
1011 = Software Updates Node
2011 = Configuration Baselines Node
5000 = Device Collections Node
6000 = Applications Node
6001 = Configuration Items Node

Example command:

Rename-CMFolderNames -ComputerName CM01 -ObjectType 5000 -Locate PS1 -Replace PS2

78_13

SetMaxMIFSize
This cmdlet will change the value called Max MIF Size in the registry on the specified computer. The Size parameter should be given a value in hex format, e.g. 3200000 equals 50MB.  This cmdlet can be executed on a remote system by specifying a value for the ComputerName parameter. This cmdlet does not produce any output.

Example command:

Set-MaxMIFSize -ComputerName CM01 -Size 3200000

78_14

Get-PXECacheExpire
This cmdlet will get the value called CacheExpire in the registry. The CacheExpire registry value specifies for how long a client must wait before initiating another Operating System Deployment when PXE booting. This cmdlet can be executed on a remote system by specifying a value for the ComputerName parameter.

Example command:

Get-PXECacheExpire -ComputerName CM01

78_15

Set-PXECacheExpire
This cmdlet will set the value called CacheExpire in the registry. The CacheExpire registry value specifies for how long a client must wait before initiating another Operating System Deployment when PXE booting. The parameter Value is specified in seconds. This cmdlet can be executed on a remote system by specifying a value for the ComputerName parameter.

Example command:

Set-PXECacheExpire -ComputerName CM01 -Value 120

78_16

Nickolaj Andersen
Principal Consultant and Enterprise Mobility MVP. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows deployments and Automation. In 2015 Nickolaj was awarded as PowerShell Hero by the community for his script and tools contributions. Author of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService and a frequent speaker at user groups.

(364)

comments
  • Kiran
    Posted at 08:01 February 20, 2015
    Kiran
    Reply
    Author

    Hi,

    Could you please post how to clear the computer object and MAC ID from the SCCM database from a windows 7 Client computer

    Regards
    Kiran

  • Leave a Reply