Skip to content

Instantly share code, notes, and snippets.

View jdhitsolutions's full-sized avatar

Jeff Hicks jdhitsolutions

View GitHub Profile
@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.
#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.
#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
#requires -version 5.1
#Get-HostPrivateData.ps1
#for best results run these commands in a PowerShell console
Function Get-HostPrivateData {
[cmdletbinding()]
[outputtype("PSHostPrivateData")]
Param()
<#
@jdhitsolutions
jdhitsolutions / ProcessManager.ps1
Created June 24, 2022 17:18
This is a revised version of an AnyBox example.
#requires -version 5.1
#requires -RunasAdministrator
#requires -module AnyBox
# https://www.fresh2.dev/doc/anybox/
# this is a revised version of the example at https://github.com/fresh2dev/AnyBox/blob/main/Examples/Process-Mgr.ps1
Param([string]$Computername = $env:Computername)
$anybox = New-Object AnyBox.AnyBox
@jdhitsolutions
jdhitsolutions / MorningReport.ps1
Last active November 10, 2023 13:40
A PowerShell script to create a computer status report. In addition to the native object output, you can format the output as text or html. Read the help and examples
#requires -version 5.1
<#
.Synopsis
Create System Report
.Description
Create a system status report with information gathered from WMI using Get-CimInstanxce. T
he default output to the pipeline is a collection of custom objects. You can also use -TEXT
to write a formatted text report, suitable for sending to a file or printer, or -HTML to
@jdhitsolutions
jdhitsolutions / rtpsug-ps7-demo.ps1
Last active February 2, 2022 21:03
This is my demo file from my RTPSUG on PowerShell 7.
#requires -version 7.1.2
Return "This is a walk-through demo script file"
#region demo prep
# Are you running in PowerShell 7?
#make my errors easier to read
$host.PrivateData.ErrorForegroundColor = "yellow"
#clear any default settings
@jdhitsolutions
jdhitsolutions / PSStyleFileInfoTools.ps1
Created January 21, 2022 18:47
A set of functions for exporting and importing FileInfo settings from $PSStyle in PowerShell 7.2.
#requires -version 7.2
<#
These commands can be used to export FileInfo settings from $PSStyle and
then import them in another session. You might use the import command in
your PowerShell profile script. The file must be a json file.
#>
Function Export-PSStyleFileInfo {
[cmdletbinding(SupportsShouldProcess)]
Param(
@jdhitsolutions
jdhitsolutions / PowerShellLab_Setup.md
Last active December 4, 2023 05:43
Detailed instructions for setting up the PowerShellLab for my Pluralsight courses.

PowerShell Lab Detailed Setup Instructions

For my Pluralsight PowerShell courses, you are welcome to use any lab environment you wish. It should include an Active Directory domain with at least a domain controller, a Windows 10 client, and a Windows Server 2016 or 2019 member server. You will need to modify the course files to fit your environment. At this point in time, Windows Server 2022 remains untested for my labs.

However, I am going to recommend that you use a free PowerShell module called PSAutoLab. I encourag you to look at the README document on the project's Github repository before proceeding. If you need help with the module or its commands, you will use the repository's Issue section.

PSAutolab

Please refer to this document to assist in installing and setting up the PSAutolab module on your computer. Run all commands from an elevated Windows PowerShell

@jdhitsolutions
jdhitsolutions / Answers.ps1
Last active March 22, 2023 06:45
Some suggested solutions to PowerShell puzzles originally posted at https://jdhitsolutions.com/blog/powershell/8128/powershell-puzzles-and-challenges/
# PowerShell Puzzles and Quick Challenges
Return "This is an interactive demo script file."
<#
The answers to these puzzles are not limited to one-line commands, although some might.
Most of these problems should be solved with no more than a lines of PowerShell code
that you would run interactively at a PowerShell prompt.
This is not a test of your scripting skills although you will find it easier to
@jdhitsolutions
jdhitsolutions / Export-Musescore.ps1
Last active July 19, 2021 19:15
A PowerShell function to use the MuseScore3 command-line tools to export a score file and its parts. You will need to dot-source this ps1 file and then run the function.
#requires -version 5.1
Function Export-MuseScore {
<#
.Synopsis
Export a Musescore3 score
.Description
The command line options for Musescore 3.6 appear to not work properly or as expected