Skip to content

Instantly share code, notes, and snippets.

View joe-scalise's full-sized avatar

Joe Scalise joe-scalise

View GitHub Profile
@joe-scalise
joe-scalise / No-Idle.ps1
Created March 15, 2022 13:38
Simulates pressing scroll lock to prevent idle (screensaver etc.)
<#
.SYNOPSIS
Simulates pressing scroll lock to prevent idle.
.NOTES
Gathered from another source originally, unsure where
#>
[CmdletBinding()]
param (
[Int]$Sleep = 240,
@joe-scalise
joe-scalise / search_user_ldap.ps1
Created February 4, 2020 16:07
Simple PowerShell LDAP Query
$user="testerdouglas"
$finalResults = New-Object System.Object
$domain = "LDAP://ldap.example.com/ou=accounts,dc=example,dc=com"
$root = New-Object -TypeName System.DirectoryServices.DirectoryEntry($domain,$null,$null,"Anonymous")
$query = New-Object System.DirectoryServices.DirectorySearcher($root,"(&(objectclass=*)(uid=$($user)))")
$results = $query.findone()
$results.Properties
@joe-scalise
joe-scalise / parse-iislogfiles.ps1
Created January 14, 2020 12:39
Use PowerShell to Parse IIS Logs for String
$logPath = "C:\inetpub\logs\LogFiles\W3SVC1\"
$logFiles = [System.IO.Directory]::GetFiles($logPath, "*.log")
# $logs will store each line of the log files in an array
$logs = @()
# Skip the comment lines
$logFiles | % { Get-Content $_ | where {$_ -notLike "#[D,F,S,V]*" } | % { $logs += $_ } }
# Example search for HTTP 500
@joe-scalise
joe-scalise / search-logfile.ps1
Created January 6, 2020 12:37
Example Searching Log File w/Powershell
[datetime]$TodaysDate = Get-Date -format d
$LogPath = "c:\logs\"
$foundFiles = gci -Path $LogPath -Filter *.txt | where {($_.lastwritetime -lt $TodaysDate) -and ($_.lastwritetime -ge ($TodaysDate).adddays(-60))}
foreach ( $file in $foundFiles ) {
foreach($line in (Get-Content "$LogPath\$file" )) {
#write-host "testing $($line)."
if ($line -like "*joe*") {
write-host $line
@joe-scalise
joe-scalise / gist:c8eed26be6489d581b68fcf56d3fdc6e
Created January 6, 2020 12:18
Notes on Deleting Files in Windows
del /F /S /Q <target>
Deletes all files in target directory. Fastest, but will not get around permission issues or other stubborn file/folder issues, and also leaves behind directory structures.
rmdir /S /Q <target>
Helpful when removing an entire directory tree, and can be used to "clean up" the directory structures left behind from del command, but has same issues with certain files/folders.
robocopy <src> <target> /MIR | out-null
@joe-scalise
joe-scalise / profiles.json
Last active December 6, 2020 02:54
Windows Terminal w/Nord Color Scheme and Example Custom Profile
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
// Use New-Guid for creating custom profiles
// https://github.com/microsoft/terminal/blob/master/doc/cascadia/SettingsSchema.md
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@joe-scalise
joe-scalise / tail_windows_event_log.ps1
Last active November 9, 2018 17:06
Example on How to Tail the Windows Event Log
$latest = (get-eventlog -LogName 'Application' -Source 'docker' -Newest 1).Index
while ($true)
{
Start-Sleep -m 5000
$tail = (get-eventlog -LogName 'Application' -Source 'docker' -Newest 1).Index
[int]$grab = $tail - $latest
if ($grab -gt 0) {
get-eventlog -LogName 'Application' -Source 'docker' -newest $grab | sort index | select Index, TimeGenerated, Message
$latest = $tail
}
@joe-scalise
joe-scalise / fizzbuzz.cs
Created November 8, 2018 20:21
FizzBuzz
using System;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
for (int n = 1; n <101; n++){
if (n%3 == 0) {
@joe-scalise
joe-scalise / MSA_scheduled_task_always_running.ps1
Last active October 24, 2018 14:51
Windows Scheduled Task, with Managed Service Account, Runs Every 15 Minutes, Indefinitely.
$appPath = "testapp.exe"
# for testing with user account instead of MSA
$serviceAccount = whoami.exe
#serviceAccount = "DOMAIN\MyServiceAccount"
$taskName = "My Test Task"
$command = "-Command "". 'C:\apps\$appPath'"""
$action = New-ScheduledTaskAction -Execute $command
@joe-scalise
joe-scalise / rules.toml
Last active August 27, 2018 18:50
Example rules.toml for Traefik
[file]
# Backends
[backends]
[backends.backend-myservice]
[backends.backend-myservice.servers]
[backends.backend-myservice.servers.primary]
url = "https://192.168.1.101:8181"