Posts Tagged ‘New-Object’
I'm very happy to see more and more people getting their hands dirty with Windows PowerShell. A common challenge I see across different support forums is getting information from one part of a script to another. Very often the user has created a function and is attempting to use its output elsewhere in their script. Often I can tell the scripter is coming from a VBScript background or at least thinking that way. There's nothing necessarily wrong with writing a PowerShell script in a VBScript style, but these scripts are missing out. Let me walk you through several iterations of a function to demonstrate.   More »
Parse HOSTS file with PowerShell
Monday, March 2nd, 2009 by Jeffery Hicks
In a recent discussion in the PowerShell forum at ScriptingAnswers.com, a member was trying to parse the HOSTS file on a number of desktops. This is a thankless but probably useful task that seems perfectly suited to a scripted solution. What we came up with was a way to turn entries in the HOSTS file to objects in PowerShell. Once we have an object then we can do all sorts of fun things with it. Here is an enhanced version of the original solution.   More »
More fun with Microsoft Word and PowerShell
Friday, August 15th, 2008 by Jeffery Hicks
I needed a demonstration for one of my last online PowerShell classes on using COM objects in PowerShell. I took an old VBScript that used Microsoft Word to get document statistics such as word and page count and transformed it into PowerShell. I quickly realized I could flesh out the demo into a larger function that I can actually use. Given that I generate a lot of Word docs, being able to get some document statistics is helpful. So I created a function called Get-DocStatistic.   More »
Analyze-Packet Reloaded
Thursday, August 14th, 2008 by Jeffery Hicks
While getting caught up on my podcast back log I was listening to an episode of Mind of Root. In it Steven Murawski mentioned my Get-Packet and Analyze-Packet PowerShell scripts. One of his (legitimate) issues with Analyze-Packet was the way it presented results. The original version simply wrote information to the console. It didn't use a good object model so that you could format the results the way you wanted. I took this as a challenge to improve the script.   More »
Searching Word
Monday, July 28th, 2008 by Jeffery Hicks
One of the last tasks I needed to accomplish to get Managing Active Directory with Windows PowerShell: TFM ready for publication was to assemble all the script samples. They'll be available for download from SAPIENPress when the book is published. I knew that most of the scripts were in my primary scripts directory, but probably not all. I usually copied scripts from my test environment to my scripts directory but I knew some were bound to be missing. I didn't want to manually open 16 chapters, search for script names, check if I had the script and then move it to a new folder. I don't have time for that. But I do have time to figure out how to do it in PowerShell.   More »
Emit custom objects, rather than text, from functions and scripts
Sunday, March 23rd, 2008 by Don Jones
Whenever possible, functions (especially) and scripts (to a lesser degree) should emit custom objects, not just text. This ensures that the output of these constructs…   More »