Posts Tagged ‘scripting’

Inventory Report to XML

Thursday, June 18th, 2009 by Jeffery Hicks
Lately I seem to be answering a number of PowerShell XML related questions. When that happens I figure its time for an example. I have a script that I think originally was posted in a forum. I apologize that I didn't note where it came from. But I've enhanced it (as I am likely to do). The script reads a bare bones XML file of computernames and builds a new XML file with inventory information such as operating system, computer system, logical disks and more retrieved from WMI. My script will hopefully serve as examples for working with XML files. I also use Write-Progress so that you can track what the script is doing.   More »

Special Forces Training Needs You!

Tuesday, June 16th, 2009 by Jeffery Hicks
In case you missed it, I'll be doing our Windows PowerShell Special Forces training in Columbus, OH at the end of next month. In addition to the normal 3 day class, I'll also be offering a bonus 2 day class for more experienced PowerShellers covering advanced topics and managing Active Directory. If you are inclined, you can also sign up for the entire week at a discount. Classes will be held at in the friendly offices of Quest Software, but space is limited because these are very intense, hands-on sessions. If you've been putting off getting training, don't wait any longer. This is the most unique training event I think you'll ever experience.   More »

Select-PropertyValue

Thursday, June 11th, 2009 by Jeffery Hicks
Because PowerShell is all about the objects, I often point out to beginners to use the Select-Object cmdlet to see all the properties of an object and their values. get-process powershell | select * Using Get-Member is helpful to discover property names but sometimes you need to see a value to know which property or properties you really want to work with. That's where my Select-Object suggestion comes in. Unfortunately not every property is defined for every object so you can end up with a lot of empty properties. What I wanted was a way to only display properties for an object that have a value. Here's my solution.   More »

Write PowerShell Scripts for YOU!

Tuesday, June 9th, 2009 by Jeffery Hicks
I'm often training administrators to use Windows PowerShell or offering guidance in a number of forums. As you might imagine I see a lot of code samples. Of course I help with the immediate challenge, but often I see opportunities where a few slight tweaks to the code layout can make a difference in readability and troubleshooting. Here's what I'm talking about.   More »

June ‘09 PowerShell One-Liner

Tuesday, June 2nd, 2009 by Jeffery Hicks
In case you don't get the SAPIEN Newsletter, here's my PowerShell one-liner for the month that uses Get-Command to find scripts in your path.   More »

PowerShell Functions: Return vs Write

Tuesday, June 2nd, 2009 by Jeffery Hicks
The other day I was involved in a short Twitter debate about the relative merits of using RETURN vs Write-Object (or its alias Write) in PowerShell functions. Here's my take.   More »

Updated PowerShell TreeForm

Monday, June 1st, 2009 by Jeffery Hicks
Not too long ago I wrote a blog post about a Windows Form PowerShell script to display a folder tree. I got some feedback about an error when running the script. The problem was that I was casting a variable in one of the functions to a specific type. Normally this is considered a best practice. But in this situation the [System.Windows.Forms.TreeNode] class depends on the parent class being loaded in your PowerShell session. Even though I thought I had tested thoroughly on PowerShell v1 and v2 I must have missed something and the [System.WIndows.Forms] class was getting loaded into my shell prior to running the script, which is why I never saw the error. Anyway, I've since modified the problematic function to remove the type casting.   More »

VBScript Includes

Thursday, May 28th, 2009 by Jeffery Hicks
I've been using VBScript for a very long time. One drawback it has always had as a scripting language is an INCLUDE statement. In other languages you can use something like INCLUDE scriptfile at the beginning of the script. This would load any functions and variables in the specified script file into your current script. In PowerShell we can accomplish this by dot sourcing scripts. I never knew of a way to do the same thing with VBScript until now.   More »


Entries (RSS) and Comments (RSS).