PowerShell: Dynamic Parameters and Parameter Validation

Background on Parameter Validation PowerShell advanced functions allow their creators to specify a fair amount of metadata that describes their parameters. One huge benefit of parameter declarations in PowerShell is that it’s possible to validate input right at the parameter level, before you execute any code in the body of the function. This helps make … Read morePowerShell: Dynamic Parameters and Parameter Validation

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

PowerShell: Enable wakeup for devices

Introduction Sometimes, if you allow your computers to go to sleep regularly, you may want to ensure that they can be easily woken using their keyboards, mice, or other peripherals. End users can get confused if they are only able to wake their computer by pressing the power button; sometimes this is made even more … Read morePowerShell: Enable wakeup for devices

PowerShell: Removing a list of computers from Active Directory

@Kid_Zer0 on Twitter recently asked the following question: “Need to delete a list of computers from AD – anyone know how to do this in #PowerShell or #VBScript (List is from a file)” I’ve previously written several versions of an Active Directory cleanup script, but if you’re not seeking something that complicated, you can simply … Read morePowerShell: Removing a list of computers from Active Directory

PowerShell: Finding Currently Loaded DLLs

I was just browsing through the root\cimv2 WMI namespace this morning, using SAPIEN’s free WMI Explorer tool, when I happened across a WMI class called CIM_ProcessExecutable. In fact, what I was doing in a bit more detail, was going through the CIM_* classes, with the Instances tab selected, so I could discover if any of … Read morePowerShell: Finding Currently Loaded DLLs

PowerShell: AD / SCCM Workstation Cleanup Script Version 3.0

I just realized, I still haven’t posted the script that removes SCCM resources, alongside Active Directory cleanup. I had written a version 3.0 of a script I previously posted, but never posted it. So, here it is (I haven’t tested it in a while): Disclaimer: I am not responsible for what you do with this … Read morePowerShell: AD / SCCM Workstation Cleanup Script Version 3.0