Skip to content

Instantly share code, notes, and snippets.

View jdhitsolutions's full-sized avatar

Jeff Hicks jdhitsolutions

View GitHub Profile
@jdhitsolutions
jdhitsolutions / PSRefresh.ps1
Last active March 1, 2024 16:33
Refresh a new Windows PowerShell Installation.
View PSRefresh.ps1
#requires -version 5.1
#requires -RunAsAdministrator
#PSRefresh.ps1
<#
Update key PowerShell components on a new Windows 10/11 installation.
This script is not intended for server operating systems. The script
should be run in an interactive console session and not in a remoting session.
@jdhitsolutions
jdhitsolutions / Challenge.md
Last active February 28, 2024 04:12
PowerShell Podcast Scripting Challenge
View Challenge.md

PowerShell Podcast ScriptingChallenge

This is the PowerShell scripting challenge from my appearance on the PowerShell Podcast

Base Challenge

Using whatever tools and techniques you want, write a PowerShell function that will query the Issues section of a GitHub repository and create output showing the number of open issues by label and the percentage of all open issues. Remember that multiple labels may be used with an issue.

For example, if there are 54 open issues and the bug label is used 23 times,your output would show a count of 23 and a total percentage of 42.59 for the bug

@jdhitsolutions
jdhitsolutions / 1. PSUGInnSalzach
Last active November 9, 2023 20:21
Presentation material for PSUGInnSalzach 9 Nov 2023
View 1. PSUGInnSalzach
return "This is a demo script file."
#demo.ps1
#about me
https://jdhitsolutions.github.io
#Module layout
psedit c:\scripts\new-project.ps1
. c:\scripts\new-project.ps1
Help New-PSProject
@jdhitsolutions
jdhitsolutions / rtpsug-advparameters.ps1
Created April 6, 2023 03:19
The demonstration file from my presentation for the Research Triangle PowerShell User Group on advanced function parameters.
View rtpsug-advparameters.ps1
#requires -version 7.3
<#
No code in this file should be considered production-ready.
All code and explanations should be viewed as educational material.
You are free to re-use anything in this file in your own work.
#>
# FIND ME: https://jdhitsolutions.github.io/
@jdhitsolutions
jdhitsolutions / Send-MastodonPost.ps1
Created December 21, 2022 20:19
A PowerShell function to post a Mastodon status.
View Send-MastodonPost.ps1
#requires -version 5.1
<#
Based on a function from https://gist.github.com/dhmacher/2203582502c7ab13015db8f52e94da45
You need an access token that has at least write access to your status
* go to settings -> Development
* Click "New Application"
* Enter a name
@jdhitsolutions
jdhitsolutions / set-envvar.ps1
Last active November 10, 2023 13:08
Set a temporary environment variable in PowerShell
View set-envvar.ps1
#requires -version 5.1
#set a temporary environment variable
# example using the function alias and positional parameters: se rust_log debug
Function Set-EnvironmentVariable {
[CmdletBinding(SupportsShouldProcess)]
[alias("se")]
Param (
[Parameter(Position = 0, Mandatory)]
[ValidateNotNullOrEmpty()]
@jdhitsolutions
jdhitsolutions / ConvertTo-PSClass
Last active November 10, 2023 13:08
A PowerShell function to convert an object instance into a PowerShell class definition.
View ConvertTo-PSClass
Function ConvertTo-PSClass {
[cmdletbinding()]
[outputType([String])]
Param(
[Parameter(Position = 0, Mandatory, ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[object]$InputObject,
[Parameter(Mandatory, HelpMessage = "Enter the name of your new class")]
[ValidatePattern("^\w+$")]
[string]$Name,
@jdhitsolutions
jdhitsolutions / Get-WinEventReport.ps1
Last active November 10, 2023 13:08
A PowerShell 7 function and custom format file to analyze an event log and report on error sources. Put both files in the same folder. Dot source the ps1 file.
View Get-WinEventReport.ps1
#requires -version 7.2
#requires -module ThreadJob
if ($IsLinux -OR $IsMacOS) {
Return "$($PSStyle.foreground.red)This command requires a Windows platform.$($PSStyle.Reset)"
}
if ($host.name -ne "ConsoleHost") {
Return "$($PSStyle.foreground.red)Detected $($host.name). This command must be run from a PowerShell 7.x console prompt.$($PSStyle.Reset)"
}
Function Get-WinEventReport {
@jdhitsolutions
jdhitsolutions / Get-Status.ps1
Created August 23, 2022 21:41
A demonstration PowerShell 7 function using $PSStyle as default formatting. Put both files in the same folder. Dot source the ps1 file.
View Get-Status.ps1
#requires -version 7.2
Function Get-Status {
[cmdletbinding(DefaultParameterSetName = 'name')]
[alias("gst")]
Param(
[Parameter(
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
@jdhitsolutions
jdhitsolutions / Get-HostPrivateData.ps1
Created August 23, 2022 14:58
A PowerShell set of functions for managing host private data
View Get-HostPrivateData.ps1
#requires -version 5.1
#Get-HostPrivateData.ps1
#for best results run these commands in a PowerShell console
Function Get-HostPrivateData {
[cmdletbinding()]
[outputtype("PSHostPrivateData")]
Param()
<#