Tag: PowerShell

Speaking on Using CIM Cmdlets and CIM Sessions for the Philadelphia PowerShell User Group Tonight!

Years ago, needing something as simple as the serial number from a remote server often meant that administrators had to resort to making a trip to the remote location. Even back in those days, some administrators were savvy enough to query WMI with third party programs or scripting languages such as VBScript to retrieve this information. Although, querying WMI was kind of like black magic back in those days and it was often simply easier to travel to the remote site or spend the money to purchase Read more [...]

PowerShell Function to Stop a Windows Service with a Status of Stopping

If you're reading this blog article, you've probably tried to stop a Windows Service and it's hung or stuck with a status of "Stopping": An average Windows Admin would say "The server is going to have to be rebooted to clear up this problem". This problem can be resolved with PowerShell though without the need for a restart. The machine I'm testing these examples on just happens to be running PowerShell version 2 so I'll use the v2 syntax to see if the Get-Service cmdlet has any properties Read more [...]

PowerShell Function to Unzip Files Using the .NET Framework 4.5 with Fallback to COM

A few days ago, I saw a tweet about someone needing to extract a zip file with PowerShell and wanting to accomplish the task without loading any third party extensions so I thought I would write a function to accomplish the task. I start out by declaring the function followed by its name, it includes comment based help which is collapsed in the following image, then the [CmdletBinding()] attribute is specified to define this function as an advanced function. Then the param block is opened which Read more [...]

PowerShell Parameter Validation: Building a Better ValidatePattern with ValidateScript

Let's start out by taking a look at what the PowerShell built-in help says about the ValidatePattern and ValidateScript validation attributes: Here's what that help topic says about ValidatePattern: We'll test using ValidatePattern with an example that I used in my entry for advanced event #4 in the Script Games this year as shown in the following example: Who knows what that regular expression does? The guy who wrote this might, but probably no one Read more [...]

What does PowerShell, SQL Server, Swag, and Jambalaya all have in common?

What does PowerShell, SQL Server, Swag, and Jambalaya all have in common? SQL Saturday #234 in Baton Rouge this Saturday, August 3rd. Whether you want to learn some PowerShell or SQL, a chance to win some cool swag, network with other technology enthusiasts in the industry, or maybe you just want a free jambalaya lunch, then the place to be this Saturday, August 3rd is SQL Saturday #234 in Baton Rouge, Louisiana. I'm not sure how many tickets are available at this point before this free technology Read more [...]

Buy a PowerShell Conference in a Book and Support Save the Children Charity in the Process

Maybe money's tight this year and you're unable to attend a conference or maybe you've already gone through your training budget for the year. There's another way to attend that conference this year for little cost and what better technology than PowerShell to attend a conference on, all while supporting a great cause (Save the Children). This isn't your ordinary PowerShell book. The PowerShell Deep Dives book is designed to be like "A conference in a book" and contains 28 chapters divided up into Read more [...]

Use PowerShell to Determine the Chain of VHD’s for a Virtual Machine on Hyper-V

You want to determine what VHD's exist for the virtual machines (VM's) that are virtualized on your Windows 8 or Windows Server 2012 Hyper-V virtualization host. This may sound simple, but what if you have a base image or template that has been configured and then multiple VM's have been created using differencing disks that reference that single base image? If that weren't difficult enough to keep track of, you may also have snapshots of those VM's which are also classified as differencing disks Read more [...]

Want to Hear the Winner of the Advanced Category in the 2013 Scripting Games Speak?

Here's where you can hear me speak over the next few months: July 2013 Thursday, July 11th (Tonight), at 9:30pm Eastern Time (8:30pm Central Time) PowerScripting Podcast Guest (Winner of the 2013 Scripting Games Advanced Category) August 2013 Saturday, August 3rd SQL Saturday #234 in Baton Rouge PowerShell Fundamentals for Beginners (Speaker) Show up early as there were 60 attendees in the 48 seat room that I was assigned the last time I presented this session in person (at SQL Saturday #220 in Read more [...]

How to Create PowerShell Script Modules and Module Manifests

My entry for the Scripting Games advanced event 4 contained four separate functions: I want to create a module that contains these functions. There are several different types of modules, but what I'll be creating is a "Script Module". Modules sound like something really complicated, but script modules are actually simple. Currently, I have the functions saved as a ps1 file which I dot-source to load the functions into memory, but I want to share this tool with others so it makes more sense to Read more [...]

PowerShell Version 4 New Feature: A UserName Property Has Been Added To Get-Process Output Objects

Thanks to a tweet from Mark Schill, I discovered that Get-Process now has an "IncludeUserName" parameter in PowerShell version 4: This means no more having to use WMI to determine what processes are being run by which users: For those of us who work in a terminal services environment, this is a really big deal. I do find it odd that it was added via a switch parameter instead of just making it another property. It kind of reminds me of how the Active Directory cmdlets are implemented. Read more [...]

PowerShell Version 4 New Feature: Requires Statements Now Let Users Require Administrator Access Rights If Needed

In PowerShell version 4, there’s a new “-RunAsAdministrator” option for the #Requires statement that prevents a script from executing unless PowerShell is running as an administrator. The information about this new option from the PowerShell version 4 "about_Requires" help topic is shown in the following image. To learn more about the requires statement, run "help about_requires" from within PowerShell. Here’s the message that's displayed if this option is specified and the person Read more [...]

Using a Counter Variable in a PowerShell Workflow Foreach -Parallel Loop

As I'm sure most of my blog readers are aware, I competed in the advanced track of the Scripting Games this year and ended up doing quite well. Two first place finishes and three second places finishes with the official judges and four first place crowd score finishes. I also ended up being the overall winner of the advanced track. A few days ago someone on twitter asked me as the winner of the Scripting Games advanced track, what I would do with it? I plan to use it as a tool. I'll continue doing Read more [...]

Win a Six Month Subscription to Interface Technical Training’s Video Collection by Solving this PowerShell Puzzle!

During the 2013 Scripting Games, I won three subscriptions, each good for six months of video training at Interface Technical Training. I have a subscription already so I asked Don Jones about re-gifting my prizes since I don't need more than one subscription so here's your chance to win one. The first video training subscription that I won was given to Rohn Edwards who is the co-founder of the Mississippi PowerShell User Group. We exclude ourselves from the normal swag giveaways we have during Read more [...]

Exclusive PowerShell in a Month of Lunches Special Lunchbox Bundle Giveaway

The June meeting of the Mississippi PowerShell User Group is tomorrow night, June 11th at 8:30pm Central Time. This is a virtual (online) meeting so anyone from anywhere can join in! Our guest speaker for this month is well known author, speaker, and PowerShell MVP Jeffery Hicks. While at the PowerShell Summit back in April, Jeffery donated a limited edition PowerShell in a Month of Lunches bundle to include a special limited edition lunchbox, Learn Windows PowerShell 3 in a Month of Lunches Second Read more [...]

2013 PowerShell Scripting Games Advanced Event 6 – The Grand Finale

For me, the Scripting Games have been a great learning experience this year. I've used many PowerShell features that I hadn't used before such as splatting, ADSI, Workflows, and producing html webpages with PowerShell. I plan to write detailed followup blog articles on each of these topics over the next few months. Event 6 was definitely challenging since I hadn't used workflows before but I also knew that's what was really needed to accomplish the given task properly (In my opinion). While you Read more [...]

2013 PowerShell Scripting Games Advanced Event 4 – Auditors Love Greenbar Paper

The requirements for the 2013 Scripting Games Advanced Event 4 can be found here. For this event I created multiple functions and I'm going to quote chapter 6, section 1 of the "Learn PowerShell Toolmaking in a Month of Lunches" book written by Don Jones and Jeffery Hicks, published by Manning: A function should do one and only one of these things: Retrieve data from someplace Process data Output data to some place Put data into some visual format meant for human consumption I started Read more [...]