Skip to content

Instantly share code, notes, and snippets.

View roberttoups's full-sized avatar

Robert Toups roberttoups

View GitHub Profile
@roberttoups
roberttoups / install_powershell_7.sh
Last active January 25, 2021 19:27
Install PowerShell 7 on Raspberry Pi
#!/bin/sh
# So far this has worked with Microsoft's versioning
# Update the version # for the version you want to install
VERSION='7.1.1'
# Variables
TARBALL="powershell-$VERSION-linux-arm32.tar.gz"
BASEURI="https://github.com/PowerShell/PowerShell/releases/download/v$VERSION"
TARGETDIR='~/powershell'
URI="$BASEURI/$TARBALL"
# Update the Pi and ensure dependencies
@roberttoups
roberttoups / myip.sh
Created April 14, 2020 13:08
Quickly return current external IP address bypassing any web proxies
#!/bin/sh
nslookup myip.opendns.com resolver1.opendns.com
@roberttoups
roberttoups / create_test_files.bat
Created June 6, 2020 13:45
Create test files in Windows for copy speed tests
@echo off
fsutil file createnew 10gb.test 10737418240
fsutil file createnew 1gb.test 1073741824
fsutil file createnew 1mb.test 1048576
fsutil file createnew 1kb.test 1024
@roberttoups
roberttoups / Export-ExceedsDomainPasswordAge.ps1
Last active November 3, 2020 15:41
PowerShell snippet to export accounts to CSV outside the default domain password policy in Active Directory
# Export-ExceedsDomainPasswordAge.ps1
$TimeStamp = Get-Date -Format 'yyyyMMddHHmmss'
$MaxPasswordAgeInDays = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days
$MaxAgeDate = (Get-Date).AddDays(- $MaxPasswordAgeInDays)
$PropertyList = @('Enabled','PasswordLastSet','Name','GivenName','SurName','SamAccountName','UserPrincipalName','DistinguishedName','manager')
[System.Array]$ExportData = Get-ADUser -Filter { PasswordLastSet -lt $MaxAgeDate -or PasswordLastSet -notlike '*' } -Properties $PropertyList
$ExportData |
Select-Object -Property $PropertyList |
Export-Csv -Path (Join-Path -Path '.' -ChildPath "$TimeStamp-PasswordAgeOutsidePolicyAccounts.csv") -NoTypeInformation
Write-Host "$($ExportData.Count.ToString('#,##0')) accounts are outside of the Domain Password Policy Age of $MaxPasswordAgeInDays days." -ForegroundColor 'Red'
@roberttoups
roberttoups / Export-PasswordNeverExpires.ps1
Created November 3, 2020 15:41
PowerShell snippet to export user objects to CSV that have their password set to never expire.
# Export-PasswordNeverExpires.ps1
$TimeStamp = Get-Date -Format 'yyyyMMddHHmmss'
$PropertyList = @('Enabled', 'PasswordLastSet', 'Name', 'GivenName', 'SurName', 'SamAccountName', 'UserPrincipalName','DistinguishedName', 'manager')
[System.Array]$ExportData = Get-ADUser -Filter { PasswordNeverExpires -eq $true } -Properties $PropertyList
$ExportData |
Select-Object -Property $PropertyList |
Export-Csv -Path (Join-Path -Path '.' -ChildPath "$TimeStamp-PasswordNeverExpiresAccounts.csv") -NoTypeInformation
Write-Host "$($ExportData.Count.ToString('#,##0')) accounts are set to password never expires." -ForegroundColor 'Red'
@roberttoups
roberttoups / Export-ReversibleEncryption.ps1
Last active November 4, 2020 15:34
PowerShell snippet to export users to CSV that have reversible encryption enabled on their object.
# Export-ReversibleEncryption.ps1
$TimeStamp = Get-Date -Format 'yyyyMMddHHmmss'
$PropertyList = @('Enabled', 'PasswordLastSet', 'Name', 'GivenName', 'SurName', 'SamAccountName', 'UserPrincipalName', 'DistinguishedName', 'manager')
[System.Array]$ExportData = Get-ADUser -Filter { userAccountControl -band 128 } -Properties $PropertyList
if($ExportData.Count -gt 0) {
$ExportData |
Select-Object -Property $PropertyList |
Export-Csv -Path (Join-Path -Path '.' -ChildPath "$TimeStamp-ReversibleEncryptionAccounts.csv") -NoTypeInformation
}
Write-Host "$($ExportData.Count.ToString('#,##0')) accounts have reversible encryption enabled." -ForegroundColor 'Red'
@roberttoups
roberttoups / Export-RootKeys.ps1
Created November 4, 2020 15:39
View all the Master Root Keys in the Forest
$DomainDistinguishedName = Get-ADDomain |
Select-Object -ExpandProperty 'DistinguishedName'
$SearchBase = "CN=Master Root Keys,CN=Group Key Distribution Service,CN=Services,CN=Configuration,$DomainDistinguishedName"
Get-ADObject -Filter '*' -SearchBase $SearchBase
@roberttoups
roberttoups / Install-gMSAAccount.ps1
Created November 4, 2020 16:01
Install a Group Managed Service Account on a Windows system
$SamAccountName = 'gmsa-Account'
klist -lh 0 -li 0x3e7 purge # resets Kerberos tickets
$TestResult = Test-ADServiceAccount -Identity $SamAccountName
if($TestResult) {
Install-ADServiceAccount -Identity $SamAccountName
} else {
Write-Output "Cannot install gMSA`:$SamAccountName"
}
@roberttoups
roberttoups / GPO WMI Queries for Windows Operating Systems.md
Created November 6, 2020 20:30
GPO WMI Queries for Windows Operating Systems

GPO WMI Queries for Windows Operating Systems

Product Type

Product Type Operating System
1 Desktop OS
2 Server OS -- Domain Controller
3 Server OS -- Member Server
@roberttoups
roberttoups / Microsoft.PowerShell_profile.ps1
Created November 24, 2020 16:26
Upgraded PowerShell Profile Prompt
function prompt {
if(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
if($env:USERDNSDOMAIN) {
Write-Host "$($env:USERNAME)@$($env:USERDNSDOMAIN)" -NoNewline -ForegroundColor 'Red'
Write-Host "(ELEVATED)" -NoNewline -ForegroundColor 'White'
Write-Host ":" -NoNewline -ForegroundColor 'DarkGray'
Write-Host "[$($env:COMPUTERNAME)]" -NoNewline -ForegroundColor 'Yellow'
} else {
Write-Host "$($env:USERNAME)@$($env:COMPUTERNAME)" -NoNewline -ForegroundColor 'Red'
Write-Host "(ELEVATED)" -NoNewline -ForegroundColor 'White'