Looking Busy with PowerShell

Every once in a while, I write a short little article -- if, I can even call it that -- and then it sits around for a month or so doing nothing. It just hangs out in my drafts and stares at me. It's happened again. Instead of focusing on it any longer, I'm writing this paragraph as my excuse, so I can publish this now and move on, already.

I saw the below Tweet late last year and I had a thought.

Now, if for some reason the above Tweet is deleted some day, you may not be able to see what was included. In that case, here's what the Tweet stated: "I love how having several windows of #PowerShell open makes you look busy and/or like you know what you are doing." I'll go ahead and agree; why not?

I can see how this may give off that impression. With that quick and internal agreement, I had an idea. If PowerShell can make you look busy, then let's use PowerShell to make it appear, you're busy. We’ll open some consoles and execute some "work," all with a single invocation of a single function. I'll just be over here waiting for PowerShell to catch up with me.

The below function creates this illusion, just in case this is something you're after. Hopefully, it's not, as we all likely have some real PowerShell to read, write, and review. Me included.

Function Show-MeBeingSuperBusy {
    [CmdletBinding()]
    Param (
        [Parameter()]
        [ValidateRange(1,10)]
        [int]$ConsoleCount = 1
    )
    
    Begin {
        $Argument = '-NoProfile -Command & {1..50 | ForEach-Object {Get-PSDrive}}',
            '-NoProfile -Command & {1..50 | ForEach-Object {Get-Process}}',
            '-NoProfile -Command & {1..50 | ForEach-Object {Get-Service}}',
            '-NoProfile -Command & {1..50 | ForEach-Object {Get-Item -Path env:\}}'
    } # End Begin.
    
    Process {
        For ($i = 1; $i -le $ConsoleCount; $i++) {
            Start-Process -FilePath powershell.exe -ArgumentList ($Argument | Get-Random)
        } # End For.
    } # End Process.
    
    End {
    } # End End.
} # End Function: Show-MeBeingSuperBusy.

Show-MeBeingSuperBusy -ConsoleCount 5

And that's it. Short, simple, and hardly very helpful. Now that this "article" is gone from my drafts, I should be able to focus on something a little more helpful -- we'll see. This might be all the help someone needed from me today, however.

≥ Tommy Maynard (Twitter: @thetommymaynard)

About Tommy Maynard

IT Pro. Passionate for #PowerShell, #AWS (certified x2), & all things automation. I'm not done learning. Author in #PSConfBook. Writes at https://powershell.org.

4 thoughts on “Looking Busy with PowerShell

  1. JoelNutt

    I love this! I wrote a script not long ago that parses every PS1 file in a certain directory into a variable, then plays it back in a console window, line by line, with random intervals as to when the lines are displayed. Looks like you are busy busting out some code!

  2. jkdba

    Just add a PSReadLineKeyHandler for quick execution like ctrl+b:

    Set-PSReadLineKeyHandler -Key ctrl+B -BriefDescription 'show busy' -LongDescription "make it look like I am working" -ScriptBlock {
    param($key, $arg)

    Add-Type -Assembly PresentationCore

    [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine();
    [Microsoft.PowerShell.PSConsoleReadLine]::Insert('Show-MeBeingSuperBusy -ConsoleCount 5; clear;');
    [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine();
    }

Comments are closed.