Earlier this Spring, I released a new function called Get-TypeMember. The function is in the PSScriptTools module. I wrote about that release here. This command is an alternative to Get-Member that includes more details. The other day I pushed a new version that makes it easier to identify properties that are enumerations. The function has…
Tag: objects
Better PowerShell Properties
I was chatting with my friend Gladys Kravitz recently about some PowerShell scripting she was doing with Active Directory and the DirectorySearcher object. For a number of reasons, the Active Directory module from Remote Server Administration Tools (RSAT) is not an option. But that’s fine. Gladys is an experience AD admin and PowerShell scripter. Still,…
Pipeline Power
Last week I came across a blog post that had a decent example using PowerShell and PowerCLI to get the disk location for all virtual machines. The posted code works and does display the information you might be after. $myVMs = get-vm foreach($vm in $myVMs){ $myDisks = @($vm | get-harddisk) foreach ($disk in $myDisks) {…
Using Types with Imported CSV Data in PowerShell
The Import-CSV cmdlet in PowerShell is incredibly useful. You can take any CSV file and pump objects to the pipeline. The cmdlet uses the CSV header as properties for the custom object. PS S:\> import-csv .\testdata.csv Date : 1/18/2012 6:45:30 AM Name : Data_1 Service : ALG Key : 1 Size : 25 Date :…
Friday Fun What’s My Variable
I use scriptblocks quite a bit in my PowerShell work, often saved as variables. These are handy for commands you want to run again, but don’t necessarily need to turn into permanent functions. $freec={(get-wmiobject win32_logicaldisk -filter “deviceid=’c:'” -property Freespace).FreeSpace/1mb} Now in PowerShell I can invoke the scriptblock. PS S:\> &$freec 94079.72265625 Ok then. I have…
Friday Fun – Get Ranked Object
Earlier this week on Google Plus, Hal Rottenberg posted a PowerShell idea he had. His goal was to identify a group of objects that would be statistically significant. For example, given a collection of files, group the files by size but ranked by size so that you might have a group for the largest files,…
Friday Fun – Get Number Object
You most likely know that I’m all about the object and the PowerShell pipeline. Everything in PowerShell is an object. Pipe something to Get-Member and you can discover all of the object’s properties and methods (ie its members). Some objects, like strings, have many methods but very few properties. Some objects, like numbers have very…
Turning IPConfig DNSCache into PowerShell
Lately I’ve been writing about techniques to turn command line tools into PowerShell tools. Although I suppose the more accurate description is turning command line output into PowerShell pipelined output. The goal is to run a command line tool and write objects to the PowerShell pipeline so I can do other operations with them. Today…
Ping IP Range
Last week I came across a post on using PowerShell, or more specifically a .NET Framework class, to ping a range of computers in an IP subnet. The original post by Thomas Maurer is here. I added a comment. And after looking at this again I decided to take the ball and run with it…
Convert Text to Object
Today I have another tool in my new battle regarding turning command line tools into PowerShell tools. The bottom line is we want to have objects written to the pipeline. At the PowerShell Deep Dive in Frankfurt there was a suggestion about providing tools to help with the transformation from CLI to PowerShell and this…
Friday Fun Convert Object to Hash Table
I’ve been working on a few PowerShell projects recently and one requirement I had was to turn an object into a hash table. I thought this was something that was already handled in PowerShell but I couldn’t find a cmdlet or an easy .NET technique. So I wrote my own function, ConvertTo-Hashtable. The function is…
Select Object Properties with Values
Here’s another concept I know I’ve written about in the past but that needed an update. A common technique I use when exploring and discovering objects is to pipe the object to Select-Object specifying all properties, get-service spooler | select *. There’s nothing wrong with this approach but depending on the object I might get…
Pipelines, Consoles and Hosts
I continue to come across a particular topic in discussion forums that causes many PowerShell beginners a lot of headaches and more than a little frustration. I know I’ve written about this before and I’m sure I’ll cover it again, but when writing anything in PowerShell that you see in the PowerShell console, you have…
Objects are the answer
As I usually do, I was helping out in the forums at ScriptingAnswers.com. A member had several variables that he wanted to show as a group. As is almost always the case, the answer in PowerShell is object. I talk about this all the time in classes, conferences and online chitchat. Let me offer up…
New WMI Object
I have one more variation on my recent theme of working with WMI objects. I wanted to come up with something flexible and re-usable where you could specify a WMI class and some properties and get a custom object with all the classes combined. My solution is a function called New-WmiObject. Function New-WMIObject { [cmdletbinding()]…