Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday the 13th PowerShell Fun

Posted on December 13, 2013

friday13 Well here are once again and another Friday the 13th. I love these days because I feel challenged to come up with 13 PowerShell related tidbits which I hope you'll find fun and maybe even a little educational.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

Today's collection should work primarily on PowerShell 3.0. Most items might also work on PowerShell 2.0. A few items will definitely require PowerShell 4.0.

#requires -version 3.0

<#
Most of these will also work on v2. A few are v4 examples

  ****************************************************************
  * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *
  * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK.  IF   *
  * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *
  * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.             *
  ****************************************************************
 #>

#1 Get 13 to the 13th power
[math]::Pow(13,13)

#2 Create a 13 character string with PowerShell 4.0
-join (33..123 | Get-Random -count 13).ForEach{$_ -as [CHAR]}

#for v3
-join (33..123 | Get-Random -count 13 | ForEach{$_ -as [CHAR]})

#3 Get the 13th process
Get-Process | Select -Skip 12 -first 1

#4 Get 13 odd numbers
1..50 | where { $_%2} | Select -first 13

#or in v4
(1..50).where{ $_%2} | Select -first 13

#5 Get 13!
1..13 | foreach -begin {$x=1} -Process {$x*=$_} -end {$x}

#6 Count by 13s
for ($i=13; $i -lt 100; $i+=13) {$i}

#7 Get 13 oldest temp files
dir $env:temp -file | Sort LastWriteTime | Select -first 13

#8 Get the square root of 13
[math]::Sqrt(13)

#9 Get the date and time in 13 days 13 hours 13 min and 13 seconds
(Get-Date).Add("13:13:13:13")

#10 Get the date and time that was 13 days 13 hours 13 min and 13 seconds in the past
(Get-Date).Subtract([timespan]"13:13:13:13")

#11 Open the 13th most recent post on PowerShell.org in a browser
Start-Process (Invoke-RestMethod -Uri http://powershell.org/wp/feed/)[12].Link

#12 Create 13 dummy test accounts in your domain
1..13 | foreach { net user "TEST$_" P@sswOrd123 /add /domain }

#or remove
1..13 | foreach { net user "TEST$_" /delete /domain}

#13 Get the next Friday the 13th.
$i=0
do {
 $i++
 $next = (Get-Date).AddDays($i)
} until ($next.DayOfWeek -eq "Friday" -AND $next.Day -eq 13)

Write-Host "The next Friday the 13th is in $i days on $($next.ToShortDateString())." -ForegroundColor Red

I'm not even going to show you any results. I'll let you try them out on your own. Enjoy and stay out of the lake today.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

4 thoughts on “Friday the 13th PowerShell Fun”

  1. jvierra says:
    December 13, 2013 at 9:43 am

    #Get the 13th of the Common Era:


    ([datetime]0).Add("12:13:13:13").AddYears(12).ToString('MM-dd-yyyy HH:mm:ss')

  2. jvierra says:
    December 13, 2013 at 9:57 am

    And since you are madly collecting 13 type things, here are all Friday the 13ths in the past:

    $d=([datetime]0).AddDays(4)
    while($d -lt [DateTime]::Today){$d=$d.AddDays(7);if($d.Day -eq 13){$d.ToLongDateString()}}

    1. Jeffery Hicks says:
      December 14, 2013 at 9:08 am

      Thanks!

  3. Jeffery Hicks says:
    December 13, 2013 at 12:05 pm

    Here’s a bonus trick: Get the last 13 lines of a log file:

    get-content C:\windows\WindowsUpdate.log -last 13

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d