This morning there was some discussion on Twitter about when to use Write-Verbose and when to use Write-Debug. They both can provide additional information about what your script or function is doing, although you have to write the code. Typically, I use Write-Verbose to provide trace and flow messages. When enabled, it makes it easier…
Category: PowerShell v2.0
Get Shared Resource
I was poking around WMI the other day in PowerShell and was intrigued by the Win32_Share class. This is a great way to find out what items are shared on a server such as printers and folders, although it’s not limited to those types of resources. I thought this would make a useful function; one…
Find Non System Service Accounts with PowerShell and WMI
As easy as Get-Service is to use in PowerShell, it has one limitation for IT Pros: it can’t show you what account the service is running under. In old school terms, “What is the service account?” Fortunately you can get that information using WMI. Here’s a query you can use that takes advantage of some…
Get Top Level Folder Usage
This is too long to tweet, even written as a one liner. But this will search a folder for top level subfolders and return the file usage for each. [cc lang=”PowerShell”] $folder=”S:\” dir $folder | where {$_.psIscontainer} | foreach { $stat= dir $_.fullname -recurse | Measure-Object -property length -Sum New-Object PSObject -property @{Folder=$_.FullName;Files=$stat.count;Size=$stat.Sum;}} [/cc] Again,…
Get Properties with Values
One of my nuisance issues when using WMI with Windows PowerShell, is that when looking at all properties I have to wade though many that have no value. I’d prefer to only view properties that have a populated value. Here’s one way.
Get Local Administrators with WMI and PowerShell
Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn’t really worked with the WMI approach in any great detail so I thought I’d see…
Get File Utilization by Extension
In the past I’ve posted a few PowerShell functions that provide all types of file and folder information. The other day I had a reason to revisit one of them and I spent a little time revising and expanding. This new function, Get-Extension will search a given folder and create a custom object for each…
Managing VirtualBox with PowerShell
In my line of work I simply can’t afford not to use virtualization, and I use just about all the major tools from time to time. But most of the time I rely on the free VirtualBox program from Oracle. One of the reasons I like it is it’s relatively low footprint. It is not…
Get PowerShell View Definitions
When you write objects to the pipeline in Windows PowerShell, at the end of the pipeline PowerShell’s formatting system handles displaying the results to the console. It accomplishes this by using a set of rules stored in XML configuration files. This is why when you run Get-Process you get a table with a pre-defined set…
Creating ACL Reports
I saw a tweet this morning that was a PowerShell one-liner for capturing folder permissions to a text file. There’s nothing wrong with it but it’s hard to be truly productive in 140 characters so I thought I would take the idea and run with it a little bit. Here are some ways you might…
Test Port 2.0
A few years ago I updated a PowerShell script I came across to scan a computer for open ports. My initial revision was aimed at making it more pipeline friendly in PowerShell v1.0. I recently needed to use the function for a project and realized it could benefit from a 2.0 upgrade.
Friday Fun: Start-TypedDemo v2
Not too long ago I posted a function I wrote for doing PowerShell demonstrations. My goal was to simulate a live interactive demo but without the typing so I could focus on explaining and not typing. The first version was a good start but I always had plans for a more feature complete function including…
TechEd Atlanta – Managing the Registry with PowerShell
My second TechEd talk was about managing the registry with Windows PowerShell. If you were in the session you know that I stressed heavily using the PowerShell provider and cmdlets. For remote computers, leverage PowerShell’s remoting infrastructure. But I also discussed using the “raw” .NET classes as well as WMI (if you are really desperate…
TechEd Atlanta – Troubleshooting with RSoP
I thought my session on troubleshooting with Group Policy and Resultant Set of Policy (RSoP) went rather well. I got some great questions and some nice feedback. The session was recorded and you can watch it on the TechEd North America site, even if you didn’t attend. Click here for the session page and video….
Get Process Detail
The other day I posted a snippet of code that I as using to monitor process memory utilization for a few web browsers. I thought the information and technique were useful enough to modularize in the form of a function. Perhaps I want to check working set on a different process or even on a…