Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
@stammy
stammy / index.xml
Created January 25, 2011 15:00
RSS Feed for Jekyll (feed/index.xml) - paulstamatiou.com
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text" xml:lang="en">{{ site.root_desc }}</title>
<link type="application/atom+xml" href="http://paulstamatiou.com/feed/" rel="self"/>
<link type="text" href="http://paulstamatiou.com" rel="alternate"/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
@chilversc
chilversc / Microsoft.PowerShell_profile.ps1
Created February 22, 2011 22:46
PowerShell profile
function Get-HomeLocation {
# Using 'Run as administrator' does not set $Home, so try other variables as well
if ($variable:Home) {
$variable:Home
} elseif ($env:Home) {
$env:Home
} elseif ($env:UserProfile) {
$env:UserProfile
} else {
$null
@JohnL4
JohnL4 / Make-Zips.ps1
Last active February 7, 2020 16:31
PowerShell cmd to zip up a directory while excluding multiple subdirectories
ls -rec | ? {-not ($_.FullName -match '\\(NUnitConsole|TestRun)\\')} | write-zip -output "$(datefn).zip"
#### If you want to get fancier...
# (1) Make a list of files touched in the last hour.
$fs = ls c:\work\sxa\18.4cu2\Projects\VisitRecord\VRDotNet\Portal\SXA.VR.Portal\bin `
| ? {$_.LastWriteTime -ge (Get-Date).AddMinutes(-60)}
# (2) Add to it. The '+=' operator actually makes a new Array by copying the old Array + the entry(ies).
@JohnL4
JohnL4 / Get-WindowsServicesAndTasksWithHardcodedPasswords.ps1
Last active August 23, 2022 18:05
PowerShell command to find logon account of Windows services; also cmd line to dump attributes of scheduled tasks to CSV file
<#
This might help in finding that pesky windows service that's always locking you out when you change your password and reboot.
#>
# ft is Format-Table; -auto is auto column width; -wrap is wrap text if necessary
Get-WmiObject win32_service | sort startname,startmode,state,displayname | select StartMode,State,StartName,DisplayName | ft -auto -wrap
# Or you can select only certain services.
# '?' is 'where' alias; -match uses regular expressions; -not is (obviously) a 'not' operator.
Get-WmiObject win32_service | ? {-not ($_.state -match 'running')} | sort startname,displayname | select StartMode,State,StartName,DisplayName | ft -auto -wrap
@kingspp
kingspp / logging.py
Created April 22, 2017 07:14
Python Comprehensive Logging using YAML Configuration
import os
import yaml
import logging.config
import logging
import coloredlogs
def setup_logging(default_path='logging.yaml', default_level=logging.INFO, env_key='LOG_CFG'):
"""
| **@author:** Prathyush SP
| Logging Setup
@JohnL4
JohnL4 / literals.ps1
Last active May 26, 2022 18:51
PowerShell syntax for complex literals (array, hash), custom objects and calculated properties
# Hash table syntax is @{ name = value; name = value; ... } -- Curly braces and semicolons
$map = @{ key1 = "value1"; key2 = 3.14 }
echo $map.key1 # "value1"
echo $map["key2"] # 3.14
# Coerce it to a new object
[PSCustomObject] $map
# Btw, you can SELECT a "calculated property" (or synthetic property, if that's how your brain works):
ls $src | ? {$_.LastWriteTime -ge (Get-Date).AddMinutes( -5)} | cp -dest $dest -for -pass
@JohnL4
JohnL4 / Process-Pipeline.ps1
Last active September 1, 2023 19:43
awk-like BEGIN and END processing of a pipeline in PowerShell; adding -Verbose and -WhatIf support via CmdletBinding
<#
.SYNOPSIS
Process pipeline junk
.NOTES
The mere presense of CmdletBinding() gives the -Verbose (-vb) parameter, so all Write-Verbose statement actually work.
Adding SupportsShouldProcess=$true gives -WhatIf, and all things this function/script does that can affect the system get turned
into verbose dry run ops.
#>
[CmdletBinding(SupportsShouldProcess=$True)] # Attribute goes on 'param' keyword.
@JohnL4
JohnL4 / Search my gists.md
Last active May 6, 2021 16:11 — forked from santisbon/Search my gists.md
How to search gists

Enter this in the search box along with your search terms:

Get all gists from the user santisbon.
user:santisbon or user:@me

Find all gists with a .yml extension.
extension:yml

@JohnL4
JohnL4 / Check-Services.ps1
Last active April 18, 2024 21:02
Check on certain windows processes & services
get-service sisense* | select Status,Name,StartType | ft -au -wr
Get-CimInstance -ComputerName p8SisMnWeb01s,p8SisMnWeb02s,p8SisMnWeb03s -ClassName Win32_Service `
| ? {$_.Name -match 'sisense.*'} `
| select PSComputerName,State,ProcessID,Name,StartMode,StartName `
| sort PSComputerName,Name `
| ft -au -wr
ps *Sisense*,*Elasticube* | select ProcessName,StartTime,Path,Description | sort StartTime -desc | ft -au -wr