Skip to content

Instantly share code, notes, and snippets.

View billkindle's full-sized avatar
🏠
Works from home and likes it that way.

Bill Kindle billkindle

🏠
Works from home and likes it that way.
View GitHub Profile
@billkindle
billkindle / Do-SearchStringUntil.ps1
Created July 20, 2020 15:59
Just a little PowerShell Do-Until loop I used for searching an active log file.
do {
# set variables for searching Service.log
$now = Get-Date -Format 'yyyy-MM-dd'
$log = 'C:\Users\wkindle\Desktop\Service_Test.log'
$logstr = 'updating status to READY'
Write-Output "Searching for READY status"
# using this to create a timeout counter
@billkindle
billkindle / Declaration_of_Independence.txt
Created June 30, 2020 15:12
Declaration of Independence
When, in the course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume, among the powers of the earth, the separate and equal station to which the laws of nature and of nature’s God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.
We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable rights, that among these are life, liberty, and the pursuit of happiness. That, to secure these rights, governments are instituted among men, deriving their just powers from the consent of the governed. That, whenever any form of government becomes destructive of these ends, it is the right of the people to alter or to abolish it, and to institute new government, laying its foundation on such principles, and organizing its powers in such form, as to them shall seem most li
# Any URL you want to test
$url = 'https://www.google.com'
# This will gather everything but that's OK
$http = (Invoke-WebRequest -Uri $url)
# I'm using the $http object membertype property to get the status code
Write-Output $http.StatusCode
@billkindle
billkindle / Get-ErrorTypes.ps1
Last active July 13, 2019 15:07
This PowerShell code will return all currently loaded .NET error types. Usefull for Try / Catch / Finally blocks.
# Courtesy of https://www.sconstantinou.com/powershell-try-catch-finally/
# A great PowerShell blogger, Stephanos Constantinou
([appdomain]::CurrentDomain.GetAssemblies() |
Where-Object {$_.Location -ne $null} |
foreach {$_.GetExportedTypes() |
Where-Object {$_.Fullname -match 'Exception'}}).FullName
@billkindle
billkindle / Get-ExeStringOut.ps1
Created July 7, 2019 16:06
Capture string output from EXE
# Send STDOUT to a string variable so it can be parsed later in a script
# WIP - Not fully tested yet
$StrOutput = [string] (& myApp.exe 2>&1)
@billkindle
billkindle / Get-LatestJRE.ps1
Created June 11, 2019 02:23
This script will download the latest Offline JRE installer for Windows x86 and x64.
<# Get-LatestJRE.ps1
Reference:
http://servertechs.info/automating-java-download-and-deployment-with-powershell-and-sccm/
#>
# First I need to obtain some Uri's from Oracle. I'll sort them out, grabbing only the Windows Offline links
$Links = $(Invoke-WebRequest 'http://www.java.com/en/download/manual.jsp' -UserAgent 'Mozilla/5.0 (Windows NT 6.1; wow64)').links |
Where-Object -Property innerHTML -like 'Windows Offline*' |
@billkindle
billkindle / Save-CommonModules.ps1
Last active December 11, 2020 04:54
I use this small script to occasionally update my most used modules so I can copy them to systems I manage or to a network share.
# These are moudles that I need to routinely save from the PowerShell Gallery
$modules = @("Pester","dbatools","dbachecks","psTrustedHosts","PoshWSUS","PSWindowsUpdate","PSDecode","PoshRSJob","PSFramework",
"ScheduledJobTools","WindowsCompatibility","ImportExcel","BurntToast","Invoke-CommandAs","PoshEvents","psbbix","UniversalDashboard.Community")
$path = Read-Host -Prompt 'Please enter the full path to which you want to save common modules:'
Foreach ($module in $modules) {
Save-Module -Name $module -Path $path -AcceptLicense -Force
@billkindle
billkindle / Get-DnsPTR.ps1
Last active April 15, 2019 19:20
I had to find out if a PTR existed or not. First time I got to use DNS PowerShelll cmdlets and ran into some minor issues.....
<# This link helped me solve the error I was recieving:
https://powershell.org/forums/topic/get-dnsserverresourcerecord-fails-on-dns-server/
Big thanks to Logan B.!
#>
# Using a splatted array here, will make final cmd shorter!
$splat = @{
Name = 'hostname'
ComputerName = 'DNSserverName'
@billkindle
billkindle / Save-CommonModules.ps1
Last active December 11, 2020 04:54
A small script to get the latest PowerShell modules I regularly use.
# These are moudles that I need to routinely save from the PowerShell Gallery
$modules = @("Pester","dbatools","dbachecks","psTrustedHosts","PoshWSUS","PSWindowsUpdate","PSDecode","PoshRSJob","PSFramework",
"ScheduledJobTools","WindowsCompatibility","ImportExcel","BurntToast","Invoke-CommandAs","PoshEvents")
$path = Read-Host -Prompt 'Please enter the full path to which you want to save common modules:'
Foreach ($module in $modules) {
Save-Module -Name $module -Path $path