//Re-Use PowerShell Scriptblocks// I commented on a blog post today that showed how to use a hash table with Select-Object to format file sizes say as KB. dir $env:temp -rec | select fullname,@{Name="KB";Expression={$_.length/1kb}} Since you most likely will want to use something similar for other directories, don't feel you have to re-invent the wheel. Save…
Tag: Scripting
The PowerShell Day Care: Building ScriptBlocks
Good morning kids and welcome to the PowerShell Day Care center. We offer a creative and nurturing environment for PowerShell professionals of all ages. Later there might even be juice and cookies. But first let’s get out our blocks, our scriptblocks, and start building. I’ve written a number of posts on script blocks and today…
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…
Friday Fun Export Transcript to Script
Over the years I’ve posted variations on this technique and discuss it often in my training classes. The idea is to take your PowerShell transcript and transform it into a PowerShell script. Remember that there is very little difference between running commands in the shell and in a script. Thus, any commands that have been…
Friday Fun Add Scripting Signing to the ISE
Today’s fun involves adding a menu item to the PowerShell ISE to make it easy to sign your scripts. I’m not going to go into the details about getting and installing a code signing certificate. I also assume you only have one installed. You can get this certificate by seasrching the CERT: PSDrive. [cc lang=”PowerShell”]…
Filtering Empty Values in PowerShell
I saw this tip today and wanted to leave a comment but couldn’t see how. So I thought I’d post my comments here. This is actually a question I see often and there are better ways to write this kind of code. The posted tip used an example where you wanted to find processes where…
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…
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…
ScriptBlocks On the Fly
I’m always preaching about writing PowerShell scripts and functions with reuse and modularization in mind. You should never have to write the same block of code twice. But what about in the shell during your daily grind? Perhaps today you’re dealing with some issue and periodically need to run a particular block of code. Now,…
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…
Get GPO Backup
The GroupPolicy module from Microsoft offers a great deal of functionality from a command line. In terms of regular maintenance or administration it is pretty hard to beat, especially if you have 100s or 1000s of GPOs. When you have such a large number, backing them up is critical and easy to accomplish with the…
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…
Process Snapshot
Yesterday I ended up running an impromptu browser test, comparing memory utilization. See what Twitter can do to your time!! The browsers themselves are really irrelevant. What you might find useful is the little PowerShell code I put together to periodically check and compare the browser processes.