This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-DfsnFolder -Path \\internal.contoso.com\dfsroot\* | Get-DfsnFolderTarget | ? {$_.State -eq "Online"} | Group-Object -Property Path | ForEach-Object {$_.group[0]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.DESCRIPTION | |
Retrieve a list of Australian government (.gov.au) domains from the CKAN Data API at https://data.gov.au/ | |
#> | |
# https://data.gov.au/dataset/ds-dga-4d5301b2-bc64-4774-b437-56a408836e57/details | |
$dataUri = 'https://data.gov.au/data/api/3/action/datastore_search?resource_id=507f8129-b84c-4215-ae7d-5aca364e4a0e&limit=2000' | |
# Basic function to strip the URL down to the bare FQDN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retrieve SPF records for a domain via Cloudflare DoH | |
$domain = 'example.com' | |
$result = Invoke-RestMethod -Uri "https://cloudflare-dns.com/dns-query?name=$domain&type=TXT" -Headers @{'accept'='application/dns-json'} | |
if ($result -ne $null) { | |
if ($result.answer -ne $null) { | |
$result.answer | Select-Object -ExpandProperty data | Where-Object {$_ -like '*v=spf1*'} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
------------------------------------------------------------------------------------------------------------- |