Trevor Sullivan's Tech Room

Minding the gap between administration and development

Posts Tagged ‘automation’

PowerShell / ConfigMgr: Count of Client Manufacturer / Models

Posted by Trevor Sullivan on 2011/11/09


If you’re an administrator of Microsoft System Center Configuration Manager (SCCM / ConfigMgr) 2007, you might be interested in finding out what make / model of client & server systems you have, and how many of each unique value you have. Most people would probably simply pull up a ConfigMgr report, but did you know that there’s an automated way to get this information as well?

Using PowerShell

You’ll need the following to execute this simple script:

  • A user account with access to the ConfigMgr provider
  • The hostname of the ConfigMgr central site server
  • The site code of the ConfigMgr central site

Once you’ve launched PowerShell under the appropriate account’s credentials, simply run this command:


$ComputerSystems = Get-WmiObject `
    -Namespace root\sms\site_000 `
    -ComputerName `
    -Class SMS_G_System_Computer_System

$ComputerSystems `
    | Group-Object -Property Manufacturer,Model `
    | Where-Object { $_.Count -gt 5 } `
    | Sort-Object -Property Count -Descending

If you get an error saying "An empty pipe element is not allowed" then make sure that there is not a space after one of the backticks. The backtick is the continuation character, and tells PowerShell to keep processing the command on the next line, and if there is a space after it, the interpreter will get confused.

If everything works as expected, you should see output similar to the following:

Count Name                    
—– —-                    
  222 Dell Inc., OptiPlex 780 
  136 Dell Inc., OptiPlex GX620

  135 Dell Inc., OptiPlex 755 
  134 Dell Inc., OptiPlex 745 
  101 Dell Inc., OptiPlex GX280

There will also be a “group” property, which contains the actual .NET objects that were grouped into each line item.

Hope this helps!

Posted in configmgr, powershell, scripting, tools, wmi | Tagged: , , , , , , , , , , , , | Leave a Comment »

PowerShell: Ping Host List from Text File

Posted by Trevor Sullivan on 2011/10/26

Here’s a quick PowerShell script to ping a list of hosts (computers, or other IP endpoints) from a text file. In addition, it eliminates error messages, which results in a filtered list of hosts that are alive. It runs quickly, because the ping count has been restricted to 1, from the default of 4.

foreach ($Client in Get-Content -Path (Read-Host).Replace('"',''))
    Test-Connection -ComputerName $Client.Trim() -Count 1 -ErrorAction SilentlyContinue

The reason it has the call to the String.Replace() method is because, if you use the Copy as Path feature in Windows 7 Explorer to feed the input to the script, it includes double quotes around the path. In this script, we don’t actually need the double quotes, because that will confuse the Get-Content cmdlet’s –Path parameter.

The call the String.Trim() is present because in my test input text file, some computer names had whitespace after them; this call cleans that up.

Posted in powershell, scripting, tools | Tagged: , , , , , | Leave a Comment »

PowerShell: Update your ConfigMgr OSD Boot Images to WinPE 3.1

Posted by Trevor Sullivan on 2011/10/21

When you upgrade your boot images in Microsoft’s System Center Configuration Manager (SCCM / ConfigMgr) 2007 from WinPE 3.0 to WinPE 3.1, you must run the ExportDefaultBootImage() WMI method on the SMS_BootImagePackage WMI class for each boot image architecture. Typically this would simply include x86 (32-bit) and x64 (64-bit) boot images (Windows Image Format (WIM) files).

There are a few different methods of running this WMI method:

  • Manually through wbemtest
  • Using the VBscript scripting language
  • A PowerShell script

Since the first two methods have been covered already by other people, I will show an example of using Windows PowerShell to call the method. Simply replace the SCCMServer and SiteCode variables with the appropriate values, and WIM paths with your own, and run the script.

$SccmServer = 'MySccmServer'
$SiteCode = '123'
$BootImageClass = [wmiclass]"\\$SccmServer\root\sms\site_$SiteCode`:SMS_BootImagePackage"

$WimFiles = @{
    'x86' = '\\$SccmServer\SMS_$SiteCode\OSD\boot\i386\winpe.x86.3.1.wim' 
    'x64' = '\\$SccmServer\SMS_$SiteCode\OSD\boot\x64\winpe.x64.3.1.wim'

$BootImageClass.ExportDefaultBootImage('x64' , 1, $WimFiles.x64)
$BootImageClass.ExportDefaultBootImage('x86' , 1, $WimFiles.x86)

Posted in configmgr, OSD, powershell, scripting, wmi | Tagged: , , , , , , , , , | Leave a Comment »

PowerShell: Determine Number of Parameters on Cmdlets

Posted by Trevor Sullivan on 2011/08/17

In PowerShell, each “cmdlet” has input and output parameters. Cmdlet definitions (including their names, parameters, parameters sets, attributes, etc.) are rich objects, just like every other object in PowerShell. Because of this, we can easily find out which cmdlets have the most parameters.

We follow this process to retrieve the information mentioned above:

  1. Retrieve a list of cmdlets available in the current PowerShell session
  2. Select the Name and parameter count (the latter, using a “calculated property” expression)
  3. Sort the results descending by parameter count

Get-Command -CommandType cmdlet | Select-Object -Property Name,@{Name = 'Parameter Count';Expression = {[int]$_.Parameters.Count} } | sort 'Parameter Count' –Descending

Here is what the results look like:

Name                                                                                                    Parameter Count
—-                                                                                                    —————
New-ModuleManifest                                                                                                   38
New-PSSessionOption                                                                                                  28
Invoke-Command                                                                                                       28
Get-WSManInstance                                                                                                    28
Get-WmiObject                                                                                                        26
Set-WmiInstance                                                                                                      25
Invoke-WmiMethod                                                                                                     25
Set-WSManInstance                                                                                                    24
Register-PSSessionConfiguration                                                                                      24
Remove-WmiObject                                                                                                     23
Enter-PSSession                                                                                                      23
Import-Module                                                                                                        23
Add-Type                                                                                                             23
Invoke-WSManAction                                                                                                   23
Set-PSSessionConfiguration                                                                                           23
Copy-Item                                                                                                            22
Set-ItemProperty                                                                                                     22
New-WSManInstance                                                                                                    22
Start-Process                                                                                                        22
Get-EventLog                                                                                                         22
New-PSSession                                                                                                        22
Send-MailMessage                                                                                                     22
Rename-ItemProperty                                                                                                  21
Get-Content                                                                                                          21

Posted in powershell | Tagged: , , , , , | Leave a Comment »

PowerShell: Happy Wifi Day!

Posted by Trevor Sullivan on 2011/08/02

PowerShell wishes you a happy Wifi day!

"Happy $(Get-Date –Format 'Mdd.yy') day!"


Posted in powershell, scripting | Tagged: , , , , , | Leave a Comment »

Orchestrator 2012: Value does not fall within the expected range

Posted by Trevor Sullivan on 2011/07/26

I was recently troubleshooting a problem with the Orchestrator 2012 Beta web service, and got the error message “Value does not fall within the expected range” when trying to start the web service IIS website from the IIS console.


Read the rest of this entry »

Posted in fixes, Orchestrator, tools | Tagged: , , , , , , , | Leave a Comment »

Orchestrator 2012: Error During Installation

Posted by Trevor Sullivan on 2011/07/25

Update: I have resolved the problem by using msizap.exe (a utility included in the Windows SDK) to kill the Orchestrator Management Service from the MSI database, and then reinstalled just that component (by running microsoft.systemcenter.orchestrator.managementserver.msi)

I’ve been repeatedly having trouble installing System Center Orchestrator 2012 on a Windows Server 2008 R2 SP1 VMware guest. My installation log is below. It seems that it is having a problem starting the service named: OpalisActionService.

Read the rest of this entry »

Posted in Orchestrator | Tagged: , , , , , , | Leave a Comment »

PowerShell: Shortening Web Service Type Names with a Hashtable

Posted by Trevor Sullivan on 2011/07/13

When you use the New-WebServiceProxy class, you probably have noticed that PowerShell dynamically generates some really ugly type names. For example, if we get a reference to the Bing web service (you’ll need to get an API key first):

$BingSearch = New-WebServiceProxy -Class BingSearch -Uri "$ApiKey"

… and examine the types contained within it:

$BingSearch.GetType().Assembly.GetExportedTypes() | select FullName

… you’ll notice some ridiculously long type names based on your API key, such as:


Read the rest of this entry »

Posted in powershell, scripting | Tagged: , , , , , , , , , , , , , , , , | 2 Comments »

Extreme PowerShell / ConfigMgr: Extending Hardware Inventory

Posted by Trevor Sullivan on 2011/07/05


In previous versions of Microsoft System Center Configuration Manager (ConfigMgr / SCCM), a common task for administrators, engineers, and consultants, was to extend the hardware inventory configuration. These inventory extensions were written in Managed Object Format (MOF) and allowed the SCCM client agents to report back a wider array of information to the central site database for reporting purposes, collection building, and other management tasks. Making changes to the configuration could be a tedious task, as MOF is not very forgiving, and rather quite strict, in its syntax.

In Microsoft Systems Management Server 2003 (SMS 2003), each time a configuration change was made, it was necessary to deploy the updated MOF file to the SMS clients — this made ensuring hardware inventory consistency across all clients a challenging task. In SCCM, Microsoft included changes to these MOF files (SMS_DEF.mof and Configuration.mof) as part of the machine policy refresh task, which is a client-side polling mechanism for configuration changes.

In SCCM 2012 Beta 2, Microsoft is taking it a step further and has eliminated the SMS_DEF.mof altogether, left the configuration.mof behind by itself, and stuck the WMI inventory configuration in … WMI. What is WMI? WMI stands for Windows Management Instrumentation, a service built into the Windows Operating System since Windows XP (and Windows 2000 Service Pack 4, I think). It provides a standard method of exposing hardware and software level system information to applications, such as storage, processor, memory, running processes, installed software, and other application configuration data. SCCM is built on top of this technology, and often makes developing software and scripts around the product much easier than it otherwise might be.

For the remainder of this article, we’re going to look at specifically how to extend hardware inventory in SCCM 2012 programmatically using Windows PowerShell with the SCCM WMI provider.

Read the rest of this entry »

Posted in .NET, configmgr, ConfigMgr vNext, powershell, scripting, tools, wmi | Tagged: , , , , , , , , , , , , , , , | 2 Comments »

PowerShell: Retrieve List of SCCM Site Codes

Posted by Trevor Sullivan on 2011/07/05

If you’re using System Center Configuration Manager (SCCM / ConfigMgr) 2007, you may want to discover how many SCCM sites you have from Active Directory. Of course, this assumes that you have Active Directory publishing enabled on your primary sites. When enabled, SCCM automatically places site information underneath the CN=System Management,CN=System,DN=mydomain,DC=com container.

Read the rest of this entry »

Posted in Active Directory, configmgr, powershell, scripting, tools | Tagged: , , , , , , , , , , , | Leave a Comment »