Skip to content

Instantly share code, notes, and snippets.

@robderickson
robderickson / inventory.yml
Created December 15, 2019 02:04
Ansible inventory with vars
all:
children:
web:
hosts:
192.168.56.3:
vars:
# These credentials are being "rejected by the server"; Can do interactive login with same credentials
ansible_user: vagrant
ansible_password: vagrant
ansible_port: 5985
@robderickson
robderickson / RunAsExplorer.md
Created October 8, 2019 19:20
How to enable 'Run as a different user' for Explorer.exe
  1. Run regedit.exe elevated.
  2. Take ownership of HKEY_CLASSES_ROOT\AppID{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}.
  3. Rename the RunAs value to _RunAs.
  4. Create a new shortcut on your Desktop for C:\Windows\System32\runas.exe.
  5. Name it something like Admin-Explorer.
  6. Right-click the new shortcut and click Properties.
  7. Change the target to: C:\Windows\System32\runas.exe /noprofile /user:<domain>\<username> "c:\windows\explorer.exe /separate"
  8. (Optional) Change the icon.
  9. (Optional) Pin to taskbar.
@robderickson
robderickson / Get-ADUserAndManager.ps1
Created May 26, 2019 15:24
Get manager details with AD user.
function Get-UserAndManager {
[cmdletbinding()]
param(
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string]$userid
)
process {
$user = $null
$manager = $null
$dirSearcher = New-Object DirectoryServices.DirectorySearcher
$dirSearcher.PageSize = 1000
$dirSearcher.SizeLimit = 100000
$dirSearcher.Filter = "(samaccountname=$username)"
$dirSearcherResult = $dirSearcher.FindAll()
$results = $dirSearcherResult | ForEach-Object {$_.Properties.title}
@robderickson
robderickson / synthwave.json
Created May 5, 2019 22:21
PSConsoleTheme theme blatantly ripping off robb0wen's SynthWave 84 VS Code theme.
{
"name": "SynthWave",
"description": "Ripped off of robb0wen's SynthWave 84 VS Code theme: https://github.com/robb0wen.",
"repository": "https://github.com/mmims",
"background": "Black",
"foreground": "Blue",
"popupBackground": "Cyan",
"popupForeground": "Gray",
"palette": {
"Black": "#262335",
@robderickson
robderickson / CertsExpiringNotice.ps1
Created September 21, 2018 19:38
CertsExpiringNotice
#Requires -Modules PSPKI
[CmdletBinding()]
param(
[string[]]$ComputerName,
[string]$From,
[string[]]$To,
[string]$Subject,
[string]$SmtpServer
)
@robderickson
robderickson / HtmlEmailStyle.ps1
Created September 21, 2018 19:35
HtmlEmailStyle
$Html = @"
<html>
<head>
<style>
body {
font-family: Calibri, sans-serif;
font-size: 11pt;
}
h2 {
@robderickson
robderickson / UpdateSplat.ps1
Created September 3, 2018 01:14
Adding key to multiple hash tables
if ($ComputerName) {
$GetADRootDSESplat['Server'] = $ComputerName
$GetADObjectSplat['Server'] = $ComputerName
$SetADObjectSplat['Server'] = $ComputerName
}
@robderickson
robderickson / Get-FailedLogonEvent.ps1
Created July 31, 2018 18:29
Get failed logon events 4771 and 4776, and return the TargetUserName and Workstation or IPAddress values recorded in the events.
[CmdletBinding()]
param(
[string[]]$ComputerName,
[string]$SamAccountName
)
PROCESS {
foreach ($computer in $ComputerName) {
$events = Get-WinEvent -ComputerName $computer -LogName Security -FilterXPath "*[System[(EventID='4771' or EventID='4776')]][EventData[Data='$SamAccountName']]"
foreach ($event in $events) {
# Get some events
$Computer = 'dc01'
$User = 'rob'
$Events = Get-WinEvent -ComputerName $Computer -LogName Security -FilterXPath "*[System[(EventID='4776']][EventData[Data='$User']]"
$xml = [xml]$Events[0].ToXml()

The document looks like this.