Skip to content

Instantly share code, notes, and snippets.

Daniel Streefkerk dstreefkerk

Block or report user

Report or block dstreefkerk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dstreefkerk
dstreefkerk / Invoke-SpeechPrank.ps1
Last active May 15, 2019
Some PowerShell pranking fun. Combine with PSRemoting to confuse your co-workers. I've not used this since 2014, so I don't know if it still works.
View Invoke-SpeechPrank.ps1
Add-Type -TypeDefinition @'
using System.Runtime.InteropServices;
[Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAudioEndpointVolume {
// f(), g(), ... are unused COM method slots. Define these if you care
int f(); int g(); int h(); int i();
int SetMasterVolumeLevelScalar(float fLevel, System.Guid pguidEventContext);
int j();
int GetMasterVolumeLevelScalar(out float pfLevel);
@dstreefkerk
dstreefkerk / Invoke-RegexReplaceTest.ps1
Created Apr 27, 2019
Some simple character replacement via Regex in PowerShell
View Invoke-RegexReplaceTest.ps1
# Regex Examples with -Replace
$testString = "ABCabc 123456_!#$%"
Write-Host "Remove all numbers in a string" -ForegroundColor Yellow
"Before: $testString"
"After: $($testString -replace '\d')"
""
Write-Host "Remove everything but numbers from a string" -ForegroundColor Yellow
"Before: $testString"
@dstreefkerk
dstreefkerk / New-ContosoUser.ps1
Created Apr 27, 2019
Generate a new AD User based upon a few specific requirements
View New-ContosoUser.ps1
# Requirements
#
# 1. Inputs - First Name, Last Name
#
# 2. SamAccountName and CN must be in firstname.lastname format
# 3. UPN must be in firstname.lastname@contoso.com format
# 4. If a user already exists with the same UPN or SamAccountName, add a number to the end or increment the existing number
function New-ContosoUser ([string]$FirstName,[string]$LastName) {
$maxUsersPerName = 100
@dstreefkerk
dstreefkerk / Get-GpoPerYear.ps1
Created Apr 1, 2019
Get a count of GPOs created per year
View Get-GpoPerYear.ps1
Import-Module GroupPolicy
$gpos = Get-GPO -All | Select-Object DisplayName,Description,CreationTime,DomainName
$gpos | Select-Object *,@{n='Year';e={$_.CreationTime | Get-Date -Format 'yyyy'}} | Group-Object -Property Year | Select-Object -Property @{n='Year';e={$_.Name}},@{n='Quantity';e={$_.Count}} | Format-Table -AutoSize
@dstreefkerk
dstreefkerk / dns_client_log.ps1
Created Mar 21, 2019 — forked from randomvariable/dns_client_log.ps1
DNS Client Logging on Windows
View dns_client_log.ps1
function Start-DNSClientLog {
$DnsOpLog = Get-WinEvent -ListLog Microsoft-Windows-DNS-Client/Operational
$DnsOpLog.IsEnabled = $true
$DnsOpLog.SaveChanges()
}
function Get-DNSClientQueries {
foreach($event in (get-winevent Microsoft-Windows-DNS-Client/Operational | % { [xml]$_.ToXml() })) {
$Query = ($event.Event.EventData.Data | Where-Object { $_.Name -eq "QueryName" }).'#text'
@dstreefkerk
dstreefkerk / Invoke-Focus.ps1
Created Mar 20, 2019
Quick little script that's kinda like a browser's "Close other tabs" function, but for Windows apps
View Invoke-Focus.ps1
# Quick little script that's kinda like a browser's "Close other tabs" function, but for Windows apps
# Drop a reference to this script into your PowerShell profile as follows:
# New-Alias -Name IFM -Value "C:\Scripts\Invoke-Focus.ps1" -Force
#
# USE AT YOUR OWN RISK
#
# Daniel Streefkerk, 2019
#
# If you want it to terminate apps without cleanly closing them, uncomment the last line
@dstreefkerk
dstreefkerk / spiceworks.txt
Created Feb 1, 2019
Some SQLite queries to pull data out of a Spiceworks DB for migration to Freshservice
View spiceworks.txt
Not sure if these are still valid, wrote them back in 2015. Might come in handy for somebody.
-------------------------------------------------------------------------------------------------------------
- All comments for a specific ticket
select u.email as created_by, c.body,c.is_public,c.comment_type,c.attachment_location,c.attachment_content_type,c.attachment_name from comments as c
inner join users as u on c.created_by = u.id
where ticket_id = 5500
order by c.created_at
-------------------------------------------------------------------------------------------------------------
@dstreefkerk
dstreefkerk / Get-MsolUserWithSmsOrPhoneMfa.ps1
Created Jan 9, 2019
List all users that have SMS or Phone call as their default MFA method.
View Get-MsolUserWithSmsOrPhoneMfa.ps1
Connect-MsolService
$allUsers = Get-MsolUser -MaxResults 100000
$usersWithSmsOrPhoneMfa = @()
foreach ($user in $allUsers) {
foreach ($method in $user.StrongAuthenticationMethods) {
if (($method.MethodType -eq 'OneWaySMS') -or ($method.MethodType -eq 'PhoneAppNotification')) {
if ($method.IsDefault) { $usersWithSmsOrPhoneMfa += $user }
}
}
@dstreefkerk
dstreefkerk / Get-LenovoBiosSetting.ps1
Last active May 23, 2018
Retrieves all current BIOS settings, and lists possible values for each setting
View Get-LenovoBiosSetting.ps1
$currentSettings = Get-WmiObject -Class Lenovo_BiosSetting -Namespace root\wmi -Filter 'CurrentSetting != ""' | Select-Object -ExpandProperty CurrentSetting | Sort-Object
$allSettings = @()
foreach ($setting in $currentSettings) {
# Check if Lenovo_GetBiosSelections exists. If not, we're running on a newer system that includes returns the possible values
# as part of the current setting value
$legacyMethodExists = Get-CimClass Lenovo_GetBiosSelections -Namespace root\wmi -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if ($legacyMethodExists) {
@dstreefkerk
dstreefkerk / Create-X500ProxyAddressFromLegacyExchangeDN.ps1
Created Apr 17, 2018
PowerShell function to create an X500 proxy address from a IMCEAEX NDR
View Create-X500ProxyAddressFromLegacyExchangeDN.ps1
Function Create-X500ProxyAddressFromLegacyExchangeDN($Address) {
# As per https://support.microsoft.com/en-au/help/2807779/imceaex-non-delivery-report-when-you-send-email-messages-to-an-interna
$Address = $Address.Replace('_','/') # Replace any underscore character (_) with a slash character (/)
$Address = $Address.Replace('+20',' ') # Replace "+20" with a blank space
$Address = $Address.Replace('+28','(') # Replace "+28" with an opening parenthesis character
$Address = $Address.Replace('+29',')') # Replace "+29" with a closing parenthesis character.
$Address = $Address.Replace('IMCEAEX-','') # Delete the "IMCEAEX-" string
$Address = $Address.Split('@')[0] # Delete the "@mgd.domain.com" string
$Address = "X500:$Address" # Add "X500:" at the beginning
$Address
You can’t perform that action at this time.