Skip to content

Instantly share code, notes, and snippets.

View chrisbrownie's full-sized avatar
🛩️
computering

Chris Brown chrisbrownie

🛩️
computering
View GitHub Profile
@chrisbrownie
chrisbrownie / Compare-FileToHash.ps1
Last active January 11, 2022 04:24
Compares a file to a given hash
function Compare-FileToHash {
<#
.SYNOPSIS
Compare-FileToHash - Compares a file to a given hash and returns a boolean of whether they match or not
.DESCRIPTION
This function will compare a file to a given hash (in string format) and
returns the boolean $true or $false depending on whether the hashes match.
Supported algorithms are all those supported by Get-FileHash.
.EXAMPLE
# Alert whenever the free space on disk falls below the following factor
# .20 = 20 %
# .10 = 10 %
$alarmThreshold = ".20"
$pushoverUrl = "https://api.pushover.net/1/messages.json"
$pushoverToken = ""
$pushoverUserKey = ""
@chrisbrownie
chrisbrownie / Get-MailboxItemsByClass.ps1
Created April 3, 2017 03:26
Returns a count of mailbox items of the specified class.
<#
.SYNOPSIS
Get-MailboxItemsByClass.ps1 - Returns a count of mailbox items of the specified class.
.DESCRIPTION
This function will return a count of the number of items in a mailbox matching the specified class.
Uses EWS Managed API to perform the check
.EXAMPLE
.\Get-MailboxItemsByClass.ps1 -MailboxToSearch [email protected] -ItemStubClass IPM.Note -StoredCredentialUsername [email protected]
.LINK
https://flamingkeys.com/
@chrisbrownie
chrisbrownie / EnablePasswordWriteback.ps1
Last active February 1, 2017 23:18
Enable AAD Connect Password Writeback
Import-Module ADSync
$connector = (Get-ADSyncConnector | Where-Object {$_.Name -ilike "*AAD"}).Name
Get-ADSyncAADPasswordResetConfiguration -Connector $connector
Set-ADSyncAADPasswordResetConfiguration -Connector $connector -Enable:$true
@chrisbrownie
chrisbrownie / DisablePasswordWriteback.ps1
Created February 1, 2017 04:10
Disable AAD Connect Password Writeback
Import-Module ADSync
$connector = (Get-ADSyncConnector | Where-Object {$_.Name -ilike "*AAD"}).Name
Get-ADSyncAADPasswordResetConfiguration -Connector $connector
Set-ADSyncAADPasswordResetConfiguration -Connector $connector -Enable:$false
@chrisbrownie
chrisbrownie / Get-MailAttributes.ps1
Created December 14, 2016 23:49
Gets UPN, Mail, and primary SMTP address (from proxyAddresses)
# Show all
Get-ADUser -ldapFilter '(msExchMailboxGuid=*)' -Properties mail,UserPrincipalName,ProxyAddresses |
Select UserPrincipalName,mail,@{N="PrimarySmtpAddress";E={($_.proxyAddresses | Where {$_ -clike "SMTP:*"}).Split(":")[1]}}
# Show only where there is a mismatch
Get-ADUser -ldapFilter '(msExchMailboxGuid=*)' -Properties mail,UserPrincipalName,ProxyAddresses |
Select UserPrincipalName,mail,@{N="PrimarySmtpAddress";E={($_.proxyAddresses | Where {$_ -clike "SMTP:*"}).Split(":")[1]}} |
Where {
($_.mail.ToString() -ne $_.userPrincipalName.ToString()) -or
($_.mail.ToString() -ne $_.PrimarySmtpAddress.ToString()) -or
<#
.SYNOPSIS
TODO: Add scripts synopsis here
.DESCRIPTION
TODO: Add script description here. This should be a longer version of the synopsis
.OUTPUTS
What are the output types?
@chrisbrownie
chrisbrownie / DownloadFilesFromRepo.ps1
Created December 6, 2016 21:21
PowerShell function to download files from a GitHub repository
function DownloadFilesFromRepo {
Param(
[string]$Owner,
[string]$Repository,
[string]$Path,
[string]$DestinationPath
)
$baseUri = "https://api.github.com/"
$args = "repos/$Owner/$Repository/contents/$Path"
@chrisbrownie
chrisbrownie / FizzBuzz.ps1
Created December 4, 2016 11:39
My PowerShell solution to the fizzbuzz question https://blog.codinghorror.com/why-cant-programmers-program/
# https://blog.codinghorror.com/why-cant-programmers-program/
function FizzBuzz {
0..100 | % {
if ( ( $_ % 3 -eq 0 ) -and ( $_ % 5 -eq 0 ) ) {
"$_ fizzbuzz"
} elseif ( $_ % 3 -eq 0) {
"$_ fizz"
} elseif ( $_ % 5 -eq 0) {
"$_ buzz"
} else {
@chrisbrownie
chrisbrownie / MonitorRedirects.ps1
Created November 16, 2016 05:45
Evaluates redirects being returned by one or more URLs. Good for troubleshooting load balancers.
$urls = @(
"http://mysite.com",
"https://mysite.com.au/"
)
$tries = 100
foreach ($url in $urls) {
$targets = @()