Skip to content

Instantly share code, notes, and snippets.

View AspenForester's full-sized avatar

JB Lewis AspenForester

  • Hennepin County, MN, USA
  • Minnesota, USA
View GitHub Profile
@AspenForester
AspenForester / Convertto-T9.ps1
Created June 17, 2020 15:52
My approach to the basic problem of the June 16, 2020 Iron Scripter Challenge. Very basic, not a function.
$Text = "EnVeLoPe"
$result = switch ($Text.ToCharArray()) {
{$_ -in ('a','b','c')} { "2"; continue }
{$_ -in ('d','e','f')} { "3"; continue }
{$_ -in ('g','h','i')} { "4"; continue }
{$_ -in ('j','k','l')} { "5"; continue }
{$_ -in ('m','n','o')} { "6"; continue }
{$_ -in ('p','q','r','s')} { "7"; continue }
{$_ -in ('t','u','v')} { "8"; continue }
@AspenForester
AspenForester / get-exp.ps1
Created April 29, 2020 13:09
Exponentiation, produces the same results as the .Net method [math]::exp(). Uses the Factorial function in another of my gists
function exp ($x)
{
[double]$sum = 1
foreach ($n in (1..100))
{
$sum += [Double]([math]::Pow($x, $n)/[double](Factorial $n))
}
$sum
}
@AspenForester
AspenForester / Get-Factorial.ps1
Last active April 29, 2020 13:10
Factorial with PowerShell
function Factorial ([bigint]$x)
{
if ($x -ge 1)
{
return $x * (Factorial ($x = $x - 1))
}
elseif ($x -eq 0)
{
return 1
}
$Computers = $env:COMPUTERNAME
$sccm = Foreach ($computer in $Computers)
{
If (Test-Connection -ComputerName $Computer -count 1 -Quiet)
{
Get-WmiObject -Class CCM_SoftwareUpdate -Filter ComplianceState=0 -Namespace root\CCM\ClientSDK -Computername $Computer |
Select-object @{N='Computername';E={$_.PSComputerName}},ArticleID,Name, URL
}
}
@AspenForester
AspenForester / IS2019-2.ps1
Created July 24, 2019 21:10
Iron Scripter 2019 - 2
$Measurement = get-childitem -Path C:\temp -Recurse -File | Measure-Object -Property Length -sum -Average
[pscustomobject]@{
Count = $Measurement.Count
Average = $Measurement.Average
Sum = $Measurement.Sum
Date = Get-Date
ComputerName = $env:Computername
}
@AspenForester
AspenForester / Get-LunarPhase.ps1
Last active April 25, 2023 04:01
Gets the current local Lunar phased by assuming your location based on your public IP address, which isn't always accurate.
$PublicIP = (Invoke-WebRequest -uri 'https://api.ipify.org?format=json' | convertfrom-json).ip
$GeoInfo = Invoke-WebRequest -Uri "http://www.geoplugin.net/json.gp?ip=$PublicIP" | ConvertFrom-Json
$location = "$($GeoInfo.geoplugin_latitude),$($GeoInfo.geoplugin_longitude)"
$TZ = [TimeZoneInfo]::Local.BaseUtcOffset.Hours
$Now = Get-date -Format M/dd/yyyy
@AspenForester
AspenForester / Get-LongestSevenSegment.ps1
Last active October 12, 2018 20:49
Inspired by Tom Scott's Basics video on longest word you can create with a seven segment display. This version gets all of the longest, not just first of the longest and is lax on what letters count, allowing S and O. It also gets the word list from github, just in case any new words are invented.
$Words = (invoke-webrequest -uri https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt).content -split ("`n")
<# Or If you have already downloaded the list
$Words = Get-Content -Path .\words_alpha.txt
#>
[regex]$NonLetters = "[gkmqvwxyz]"
$LongestWords = @()
foreach ($Word in $Words)
{
@AspenForester
AspenForester / Get-FileMetaData.ps1
Last active August 2, 2018 13:06
Returns one or more objects containing all 290 metadata items available for windows files.
<#
.Synopsis
Gets all file metadata
.DESCRIPTION
Returns one or more objects containing all 290 metadata items available for windows files.
This function is based on work by Ed Wilson
https://gallery.technet.microsoft.com/scriptcenter/c3d0ea6c-64a1-4716-a262-bcd71c9925fc#content
https://blogs.technet.microsoft.com/heyscriptingguy/2009/12/29/hey-scripting-guy-how-can-i-list-all-the-properties-of-a-microsoft-word-document/
.EXAMPLE
PS C:\> Get-FileMetaData -Path c:\Users\Me\Documents
Describe "FileServer Shares" {
$FileServers = Import-PowerShellDataFile "H:\HennRepos\InfrastructureTesting\Diagnostics\simple\demodata.psd1"
Foreach ($Node in $FileServers.AllNodes)
{
Context "$($Node.NodeName)" {
# It might be desirable to ensure there is a DNS record for the server before even bothering to try and ping it
# I think I would still do the ping, let it fail and let that cause all of the share tests to be skipped.
$PingResult = Test-Connection -ComputerName $Node.NodeName -Quiet -Count 1
@AspenForester
AspenForester / Restart-HungVM
Last active June 20, 2018 19:30
Used this to rapidly restart the VMs that got stuck rebooting after being patched. There may be other ways to get the list of machines to consider for restart other than a static list.
$vis = Connect-VIServer MyVcenter
$Servers = @("SomeServers")
foreach ($Server in $servers)
{
if ( -not (Test-NetConnection -ComputerName $Server -CommonTCPPort SMB).TcpTestSucceeded )
# Or maybe some other appropriate test or tests
{
get-vm $Server | Restart-VM -Confirm:$false