The change is making the class and noun parameters mandatory. In PowerShell 3 & 4 you can simplify the syntax slightly:

param (

[Parameter(Mandatory)]

[string]$class,

[Parameter(Mandatory)]

[string]$noun,

[string]$namespace = ‘ROOT\cimv2′,

[string]$path = “C:\Scripts\Modules\Hardware”

)

I prefer to use the PowerShell 2.0 syntax and actually state that Mandatory=$true. This is for 2 reasons. Firstly, its what I’m used to and it works – I haven’t got round to changing my default templates. Secondly, I prefer to use this syntax because its immediately apparent to me that the parameter is Mandatory.

This time I’ve used the Win32_NetworkAdapterConfiguration class because it enables me to introduce the use of search (filter) parameters in CDXML cmdlets; it has a number of very useful methods and it enables me to introduce the use of format files.

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess

NestedModules = @(‘Win32_BIOS.cdxml’,

‘Win32_ComputerSystem.cdxml’,

‘Win32_DiskDrive.cdxml’,

‘Win32_NetworkAdapterConfiguration.cdxml’

)

# Functions to export from this module

FunctionsToExport = @(‘Get-Bios’,

‘Get-ComputerSystem’,

‘Get-PhysicalDisk’,

‘Get-NetworkAdapterConfiguration’

)

You now have a hardware module consisting of:

£> Get-Command -Module Hardware

CommandType Name

———– —-

Function Get-Bios

Function Get-ComputerSystem

Function Get-NetworkAdapterConfiguration

Function Get-PhysicalDisk

The output from Get-NetworkAdapterConfiguration on my Windows 8.1 virtual machine looks like this:

ServiceName DHCPEnabled Index Description

———– ———– —– ———–

netvsc False 0 Microsoft Hyper-V Network Adapter

kdnic True 1 Microsoft Kernel Debug Network Adapter

tunnel False 3 Microsoft ISATAP Adapter

netvsc False 4 Microsoft Hyper-V Network Adapter #2

tunnel False 5 Microsoft ISATAP Adapter

Now this is the same display that Get-CimInstance produces and for my purposes it doesn’t work. I need to create a format file to produce the display I need. I also want to be able to filter on various criteria including DHCPEnabled, IPEnabled, InterfaceIndex, Index and Description. I also want to be able to search on any of these individually or in any logical combination

On a Windows Server 2012 or 2012 R2 system you can install the ServerManager module and use the Get-WindowsFeature cmdlet to discover the installed features. They can be managed with Install-WindowsFeature and Uninstall-WindowsFeature .

These cmdlets don’t exist on Windows 8/8.1

However the Dism (Deployment Image Servicing and Management) module can help out. The Dism module is mainly concerned with managing wim files and virtual disks for deployment scenarios but it also contains these cmdlets:

Enable-WindowsOptionalFeature

Get-WindowsOptionalFeature

Disable-WindowsOptionalFeature

To discover the installed features

Get-WindowsOptionalFeature -Online | Format-Table –AutoSize

The output looks like this

FeatureName State

———– —–

Microsoft-Hyper-V-All Enabled

Microsoft-Hyper-V-Tools-All Enabled

Microsoft-Hyper-V Enabled

Microsoft-Hyper-V-Management-Clients Enabled

Microsoft-Hyper-V-Management-PowerShell Enabled

Printing-Foundation-Features Enabled

Printing-Foundation-LPRPortMonitor Disabled

Printing-Foundation-LPDPrintService Disabled

Printing-Foundation-InternetPrinting-Client Enabled

etc

For all of these cmdlets use –Online to access the local machine rather than an image.

About This Blog

A blog for Windows administrators, Architects, Consultants and System Integrators maximizing the use of PowerShell and WMI. Simple solutions to everyday problems using two tools that should be available on every Windows system. Save time, save effort, script now!