If you are like many IT Pros that I know, you often rely on text files in your PowerShell work. How many times have you used a text file of computernames with Get-Content and then piped to other PowerShell commands only to have errors. Text files are convenient, but often messy. Your text file might…
Category: CommandLine
Press PowerShell Pause to Continue
Everyone once in a while I come across a PowerShell script that behaves like an old-fashioned batch file. Not that there’s anything wrong with that, but often these types of scripts put in a pause at the end of script so you can see that it finished. You might have seen a command like this…
Set Local User Account with PowerShell
The other day I received an email from a student asking for some help in using PowerShell to take care of a user account on a local computer. He not only wanted to be able to set the password, which he had already figured out, but also how to enable or disable the account, which…
More Fun with String Properties
The other day I posted an article about converting string properties that you might get from running a command line tool into a PowerShell named property. I was continuing to experiment with it. Here’s some code on how I could use it. $raw = qprocess $properties = $raw[0] -split “\s{2,}” | Convert-StringProperty $raw | select…
Convert a String to a PowerShell Property Name
Over the last few years I’ve written and presented a bit on the idea of turning command line tools into PowerShell tools. We have a lot of great CLI based tools that are still worth using. What I’ve done is come up with tools and techniques for turning their output into an object that can…
Convert Text to Object with PowerShell and Regular Expressions
A few weeks ago I was getting more familiar with named captures in regular expressions. With a named capture, you can give your matches meaningful names which makes it easier to access specific captures. The capture is done by prefixing your regular expression pattern with a name. PS C:\> “UNC is \\server01\public” -match “\\\\(?<servername>\w+)\\(?<sharename>\w+)” True…
Managing Local Admin with PowerShell
Years ago when I was deep into VBScript and HTAs, I wrote a tool called PWDMan. It was an HTA that processed a list of computers and returned password age information for the local administrator account. It was also capable of setting a new account password. Apparently this is still a common task because I’ll…
Out with the Windows.old
Over the last few days I’ve started the process of upgrading my test virtual machines to Windows Server 2012 R2, or in the case of my mini Hyper-V server, to the final bits of Windows Hyper-V Server 2012 R2. In many cases I had been running the preview bits. I know I probably should have…
Turning CLI Tools into PowerShell Tools
Last night I gave a presentation for the Mississippi PowerShell User Group. My talk was based on the chapter I contributed to the forthcoming PowerShell Deep Dives book. In the chapter I explore different techniques for turning command line tools into PowerShell tools. My presentation demonstrated those techniques in action. As promised, I’ve bundled my…
Get Local Admin Group Members in a New Old Way
Yesterday I posted a quick article on getting the age of the local administrator account password. It seemed appropropriate to follow up on a quick and dirty way to list all members of the local administrator group. Normally, I would turn to WMI (and have written about this in the past). But WMI is relatively…
Friday Fun: Expand Environmental Variables in PowerShell Strings
This week I was working on a project that involved using the %PATH% environmental variable. The challenge was that I have some entries that look like this: %SystemRoot%\system32\WindowsPowerShell\v1.0\. When I try to use that path in PowerShell, it complains because it doesn’t expand %SystemRoot%. What I needed was a way to replace it with the…
Convert Text to Object Updated
I’ve had a few comments and emails lately about my post and script on converting text to objects. I decided the function needed a little more lovin’ so today I have an updated version, complete with comment based help. Function Convert-TextToObject { tasklist /s server01 /fo list | where {$_} | convert-texttoobject -group 5 Take…
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…
Simple Where Filters
The comment about how awkward it is in PowerShell to filter out folders with Get-ChidlItem, or its alias dir, came up the other day on Twitter. I’ll be the first to admit that running a DIR command and wanting to skip folders, or perhaps you only want top level folders, is more cumbersome than we…
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…