PowerShell: List Strongly Typed Names in Global Assembly Cache

I dislike using deprecated commands or APIs when I know that there’s a more modern method of performing an action. I also generally prefer to use Windows PowerShell as a .NET scripting language, rather than constantly relying on cmdlets. To be sure, I use a balance of both concepts, since cmdlets can save a whole lot of coding a lot of the time.

Every time I want to load an assembly into PowerShell, the first thing that pops into my mind is using the LoadWithPartialName() method:
[cc lang=”powershell”][Reflection.Assembly]::LoadWithPartialName();[/cc]
Unfortunately Microsoft recommends against using that static method, as it is deprecated, and recommends use of other methods such as LoadFile() or Load() like:
[cc lang=”powershell”][Reflection.Assembly]::Load(StronglyTypedAssemblyName);[/cc]
In the interest of not breaking my conscience, I would like to use this method, but the problem then becomes that I have to constantly figure out what the strongly-typed name of the assembly I want is. To help solve this problem, I decided to write a PowerShell script that extracts information from the .NET assemblies in the Global Assembly Cache (GAC), since those are generally the most common ones I’ll need to reference.

Read morePowerShell: List Strongly Typed Names in Global Assembly Cache

PowerShell 3.0: List of Windows 8 Cmdlets & Modules

Here is a list of modules available in the new Windows Server 8:

Name
—-
ADDeploymentWF
AppLocker
Appx
BestPractices
BitsTransfer
BranchCache
CimCmdlets
ClusterAwareUpdating
DirectAccessClientComponents
Dism
DnsClient
DnsConfig
DnsLookup
DnsNrpt
FailoverClusters

 

Read morePowerShell 3.0: List of Windows 8 Cmdlets & Modules

Extreme PowerShell / ConfigMgr: Extending Hardware Inventory

Introduction

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 moreExtreme PowerShell / ConfigMgr: Extending Hardware Inventory

Removing Permanent WMI Event Registrations

Introduction Since I’ve worked on the PowerEvents PowerShell module, several folks have been confused about how to remove event registrations once they’ve been created. I wrote some documentation that’s included in the download, that explains how to manually remove these registrations using the built-in wbemtest tool. This is the fool-proof method, since wbemtest is included … Read moreRemoving Permanent WMI Event Registrations

PowerShell Quick Tip: Determine STA Threading Mode

Some code in PowerShell requires you to use the Single-Threaded Apartment (STA) threading model. The PowerShell version 2.0 console host uses Multi-Threaded Apartment by default. The PowerShell Integrated Scripting Environment (ISE) uses the STA threading model. If you’re writing code using the WPK module included in the PowerShellPack, you will need to ensure that you … Read morePowerShell Quick Tip: Determine STA Threading Mode

PowerShell: Disable CapsLock

Here’s a quick code snippet that shows how to disable CapsLock using PowerShell, combined with some embedded C# and .NET Interop (aka. P/Invoke.NET) code. Credit goes to “BobS00327” for the C# code necessary to handle this. function Set-CapsLock([switch]$Disable = $true) { $CapsCtrl = @" using System; using System.Runtime.InteropServices; using System.Windows.Forms; public class CapsLockControl { [DllImport("user32.dll")] … Read morePowerShell: Disable CapsLock

PowerGUI: Save Time, Customize Snippets

Introduction Quest’s PowerGUI Integrated Development Environment (IDE) offers the ability to insert code snippets, similar to Microsoft Visual Studio. This saves a lot of typing, and gives you the general framework for whichever PowerShell construct you’re trying to us, for which you only need to fill in the specifics. These code snippets are conveniently stored … Read morePowerGUI: Save Time, Customize Snippets

PowerShell: ConfigMgr WMI Provider (feat. Lazy Properties)

What are Lazy Properties? So if you’re a script writer, and you also use System Center Configuration Manager 2007 (ConfigMgr), you may have run into a concept called Lazy Properties. Lazy properties are certain (not all) properties on certain (not all) WMI classes, within the ConfigMgr provider namespace, that are marked with a WMI qualifier … Read morePowerShell: ConfigMgr WMI Provider (feat. Lazy Properties)

PowerShell Module: Enable Wake for Devices

So in my last post, I shared a PowerShell script that enables you to enable devices to wake up computers. This script relies solely on a WMI interface, but despite the remote nature of WMI, I had provided no method of entering a remote computer name. That changes with the release of my first ever … Read morePowerShell Module: Enable Wake for Devices