Skip to content

Instantly share code, notes, and snippets.

# ------------------------------------------------------------------------------------------------------------------------
# Preferences
# ------------------------------------------------------------------------------------------------------------------------
# Setting StrictMode to enforce Coding Best Practices.
Set-StrictMode -Version 2.0
# Setting the Error Preference variable to stop to make sure that non terminating errors do terminate.
$ErrorActionPreference = 'Stop'
@SteloNLD
SteloNLD / Watch-Job.psm1
Last active July 5, 2018 22:03
Powershell Function 'Watch-Job', see the Progress of the Jobs you are running, kill all when one is failed
<#
.Synopsis
Watch Powershell Job progress.
.DESCRIPTION
This function allows you monitor the progress of the Powershell Jobs you just started,
it wil show a progressbar and the remaining jobs that are still running.
one of the key features is the ability to stop the other Jobs when 1 is failed.
.EXAMPLE
Watch-Job -Job $Jobs
Shows a progress bar indication how many jobs are completed/still running
@SteloNLD
SteloNLD / PsExample-5ad9fec0144ae4e0d0113de0b7cb626e.ps1
Last active August 3, 2023 17:12
Powershell Example: Try/Catch, ForEach, If/Else, Break/Continue, Write-Verbose/Warning/Host/Error
Clear-Host #Clearup the console.
### Script Output/Error Preferences.
#Enable/Disable Verbose Output for Debugging
$VerbosePreference = "Continue" #Use either Continue (Show) or SilentlyContinue (Hide)
#Stop Script Execution when an error occurs.
#Always use Stop!, if you need to bypass this behaviour for a specific command then use the -ErrorAction Parameter with SilentlyContinue for that command.
$ErrorActionPreference = "Stop"
@SteloNLD
SteloNLD / PsExample_Send-MailMessage_Splatting_SecureString.ps1
Last active January 30, 2020 21:39
Powershell Example: HashTables, SecureString, Splatting, Send-MailMessage
### Script Global Settings
#Declare SMTP Connection Settings
$SMTPConnection = @{
#Use Office365, Gmail, Other or OnPremise SMTP Relay FQDN
SmtpServer = 'outlook.office365.com'
#OnPrem SMTP Relay usually uses port 25 without SSL
#Other Public SMTP Relays usually use SSL with a specific port such as 587 or 443
Port = 587
UseSsl = $true
@SteloNLD
SteloNLD / Invoke-PsHTML.ps1
Last active April 19, 2018 22:22
Execute Powershell code embeded within [Ps]HTML Files.
# Executes the Powershell HTML file, code prefixed with $( and suffixed with ) will be executed.
# Part of the Portable Powershell Webserver service/script made by @SteloNLD, Sten Lootens (sten@ltns.nl).
Function Invoke-PsHTML ($PsHTML_FilePath){
Return Invoke-Expression ('@"
' + $(Get-Content $PsHTML_FilePath) + '
"@')
}
@SteloNLD
SteloNLD / Get-BulkServerServiceStatus.ps1
Last active March 1, 2024 07:01
Powershell, get status from multiple services and computers.
cls
#Services are declared here, but you can of course load them from something like a CSV file.
$Servicelist = @("WinRM", "Winmgmt", "DHCP")
#Computers are declared here, but you can of course load them from something like a CSV file.
$Computerlist = @("LocalHost", "Server1","Server2","Server3")
#HashTable, wil store the services with running status for each server,
$ServiceStatus = @{}
@SteloNLD
SteloNLD / Registry Changer.ps1
Last active March 27, 2017 11:54
Registry Changer, Adds predefined registry keys to the windows registry.
#requires -version 3
<#
.SYNOPSIS
Registry Changer
.DESCRIPTION
Adds predefined registry keys to the windows registry.
.PARAMETER UserName
Optional, The UserName to use, defaults to $env:USERNAME (the username of the current user)
.PARAMETER UserDomain
Optional, The UserDomain to use, defaults to $env:USERDOMAIN (the domain of the current user)