Eric's Technical Outlet

Learning the hard way so you don't have to

Category Archives: PowerShell

Corefig Has Been Murdered, Long Live Corefig!

The important part: I am still working on Corefig. There will be a new version. It will improve greatly upon previous versions.

The bad part: the project has suffered a serious setback. It will take some time to recover.

Read more of this post
Advertisements

Use PowerShell to Discover Long-Distance CIM (WMI) Relationships

Usually when you need information from CIM (WMI), you only need to query a single instance. Sometimes, you need to dig through a series of class relationships to find what you want. I’ve built a pair of PowerShell scripts to make that easier.

Read more of this post

Change Default Cmdlet Parameters in Script Without Changing the Global Defaults

PowerShell provides the $PSDefaultParameterValues global variable so that you can pre-configure arguments for specific parameters on cmdlets that you use regularly. But, what if you want to do the same thing in a script? What if you want to do it without breaking anything in the existing global variable? With only a bit of work, you can.

Read more of this post

Using PowerShell for Consistent, Repeatable Windows Features Selection

Deploying Windows Servers can be a pain, even when you’ve got a templating system. How do I know that the template matches my current requirements? What do I know now that I didn’t know when that template was built? How do I easily manage the one-off differences between that template and the needs of this new system?

It’s even worse when you don’t have a template system or have overriding reasons to not to use one. You’re stuck building each new server from scratch, checking those boxes like it’s your first time.

Or, are you?

If you’re looking for a fast way to save or copy the list of selected Windows Server features and roles and apply them to a new system, PowerShell can easily help.

Read more of this post

PowerShell: Find Local Applications Blocked By a Remote Firewall

I’m sure we’ve all been there. You get an application that a vendor wrote and tested on a single, unfirewalled subnet. They sell it to you and you put it in your higher-security, multi-subnetted, firewalled environment, and it all falls down and goes boom. The vendor swears they’ve given you all the firewall information and then you go around-and-around for a few days, pulling network traces, etc.

So, I have thrown together a little script suite that should help you get to the bottom of it a little more quickly. Of course, a lot of times, you open one port only to discover that there is another port that will be needed that you couldn’t detect until the first one was open. Not much I can do about that in a PowerShell script, but watch the Altaro blog because I plan to demonstrate how to set up a test environment in Hyper-V to do this whole thing in a few minutes as opposed to the hours, or even weeks, it can sometimes take otherwise.

Read more of this post

PowerShell: Use RACADM to Delete a Dell DRAC User by Index

Dell’s DRAC web interface allows you to create and modify DRAC users, but not remove them. The RACADM.EXE utility has the power to do this, but the syntax isn’t easy to remember. Rather than look it up each time, you can easily script this with PowerShell.

Read more of this post

Convert Visual Basic Form to PowerShell

Last Updated: v1.05, May 22, 2015

From time to time, I like to have my PowerShell scripts display a nice GUI. Often, I have a scheduled script with numerous configuration options, and I see no value in forcing any person who uses my scheduled script to have to decipher and retool the options when I can slap together a UI that builds the configuration file for them. That’s just one example of why you might want to have PowerShell generate a GUI. But, this post is not about the philosophy of using a GUI in PowerShell, or using PowerShell instead of a full application development environment. This is about the mechanics.

Read more of this post

PowerShell: Script that Calls Itself Recursively

To have a PowerShell script that calls itself recursively, use the following construct:

Invoke-Expression -Command $PSCommandPath

If the script uses parameters, use the following construct:

Invoke-Expression -Command ($PSCommandPath + ' -Parameter1 FixedValue -Parameter2 $VariableValue')

If you want to call the script exactly as it was initially called (be careful!):

Invoke-Expression -Command $PSCmdlet.MyInvocation.Line

Read more of this post

PowerShell: Sort a Windows Forms ListView without a Custom Comparer

I realize that PowerShell is mainly for command-line operations and scripting, but I’ve found more than a few uses to have it present a GUI. From my own portfolio, CoreFig would be a prime example. What GUIs are especially good for is presentation, selection, and manipulation of complex data structures. One control that’s suited for such uses is the ListView. Using a ListView in PowerShell isn’t more difficult than using most any other Windows Forms object. Sorting it, on the other hand, isn’t simple. Most of the solutions I found did not work at all, only did a sort-of sort, or did some complicated work with the .Net Framework. I have concocted a solution that stays in PowerShell.

Read more of this post

Removing an Adapter’s Gateway Using PowerShell

While trying to improve operations and fix some bugs in the networking module in Corefig, I encountered something interesting. The new PowerShell commands (PowerShell 3.0 cmdlets found in Hyper-V Server 2012, Windows Server 2012, and Windows 8) don’t remove gateways from adapters in the way that we NETSH users are accustomed to. Strangely, it appears that some of the workarounds users found for 2008 R2 don’t work anymore.

Read more of this post