Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / isLocked.ps1
Created August 2, 2020 05:37
Check if domain user is locked out
[bool]$isLocked = (Get-ADUser 'username' -Properties LockedOut).LockedOut
if ($isLocked -eq $True) {
Write-Host "Account is locked"
} else {
Write-Host "Account is not locked"
}
@jcefoli
jcefoli / github-auth.ps1
Created August 2, 2020 05:04
Authenticate with token to Download File from Raw Githubusercontent
$headers = @{'Accept' = 'application/json'}
$tokenString = "REPLACE-GITHUB-TOKEN-HERE" + ":x-oauth-basic"
$base64Auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(($tokenString)))
$headers.Add('Authorization',"Basic $base64Auth")
$content = Invoke-RestMethod -Uri "https://raw.githubusercontent.com/ORG/Repo/master/something.ps1" -Headers $headers
@jcefoli
jcefoli / pause-locally.ps1
Created February 4, 2020 12:48
Pause Script When Run Locally But not Remotely
#Add to end of script
if ($PSSenderInfo) {
#Script was launched remotely. Do Not Pause
}
else {
#Script is running locally, pause
[void](Read-Host 'Press Enter to continue')
}
@jcefoli
jcefoli / fizzbuzz.ps1
Created October 24, 2019 20:29
[Powershell Interview Question] The FizzBuzz Problem: Write a program that prints the numbers 1 to 100. For multiples of 3, print "Fizz". For multiples of 5, print "Buzz". FOr multiples of both 3 and 5, print "FizzBuzz".
for ($x = 1; $x -le 100; $x++) {
$Output = ""
if ($x % 3 -eq 0) { $Output += "Fizz" }
if ($x % 5 -eq 0) { $Output += "Buzz" }
if ($Output -eq "") { $Output = $x }
Write-Output $Output
}
@jcefoli
jcefoli / isLocked.ps1
Created October 15, 2019 03:37
Conditionally Check for AD Locked Out User Account
[bool]$isLocked = (Get-ADUser 'username' -Properties LockedOut).LockedOut
if ($isLocked -eq $True) {
Write-Host "Account is locked"
} else {
Write-Host "Account is not locked"
}
@jcefoli
jcefoli / sendmail.ps1
Created October 14, 2019 18:52
Send Email in Powershell via .NET Net.Mail.SmtpClient & Net.Mail.MailMessage
$message = new-object Net.Mail.MailMessage;
$message.From = "[email protected]";
$message.To.Add('[email protected]');
$message.Subject = "Test by Joe";
$message.Body = "Message body here";
$smtp = new-object Net.Mail.SmtpClient("smtp.server.local", "25");
$smtp.send($message);
@jcefoli
jcefoli / kickjenkins.ps1
Created September 24, 2019 22:32
Kick Jenkins Job With CSRF Protection Enabled [Powershell REST Request]
# Force TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Basic Auth Credentials
$user = 'changeme'
$pass = 'insecure-password'
# Handle Basic Auth (Hacky in Powershell)
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

Keybase proof

I hereby claim:

  • I am jcefoli on github.
  • I am jcefoli (https://keybase.io/jcefoli) on keybase.
  • I have a public key whose fingerprint is 1EEF B0D8 3F20 F83B 086B 888C CE34 4425 E18C 50B4

To claim this, I am signing this object:

@jcefoli
jcefoli / Disable-AeroShake.ps1
Created September 3, 2019 15:53
Disable Aero Shake (Idiotic Windows feature that minimizes all windows if you shake one window with the mouse. I do this when I'm thinking sometimes inadvertently and it annoys the hell out of me)
#Run as Admin
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "DisallowShaking" -Value "0" -PropertyType "DWord"
@jcefoli
jcefoli / dns-loadbalancing-test.sh
Last active October 8, 2019 18:06
Performs 100 dns lookups against a domain and sorts the responses. Useful for testing DNS load balancing. (Bash one-liner)
for i in {1..100}; do dig mydomain.com @my.nameserver.com +short; done | sort | uniq -c
# replace mydomain.com with your domain name
# replace my.nameserver.com with the hostname of your domain's nameserver