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 / Convert-ADGroupsToGlobal.ps1
Last active August 23, 2016 10:46
Bulk Convert AD Groups to Global
# Get all the groups in the OU we're targeting
$groups = Get-ADGroup –Filter * -SearchBase “OU=File Shares,OU=Groups,DC=Contoso,DC=com”
# Recurse through each group
Foreach ($group in $groups) {
# Make it universal
$group | Set-ADGroup –GroupScope 2
# Make it global
$group | Set-ADGroup –GroupScope 1
}
@chrisbrownie
chrisbrownie / PowerShellTTS.ps1
Last active December 29, 2016 21:41
PowerShell Text To Speech
Add-Type -AssemblyName System.speech
$ss = New-Object System.Speech.Synthesis.SpeechSynthesizer
$ss.Rate = -3
$ss.Speak("Hello I am a computer")
# Get all users with MFA enabled
# Import MSOL Module
Import-Module MSOnline
# Connect to the service
Connect-MsolService
#Find all MFA enabled users
$MfaUsers = Get-MsolUser -All | Where-Object {$_.StrongAuthenticationRequirements -like "*"}
# Import MSOL Module
Import-Module MSOnline
# Connect to the service
Connect-MsolService
# What's the AAD Sku? We'll assign this to admins
$aadSku = (Get-MsolAccountSku | Where {$_.AccountSkuId -ilike "*:AAD_PREMIUM"})[0].AccountSkuId
# Define StrongAuthentication (MFA) requirements
@chrisbrownie
chrisbrownie / Update-UPNs.ps1
Created September 1, 2015 22:15
Updates the UPN of all users in a specified location to match their primary SMTP address
$SearchBase = "DC=MargiesTravel,DC=com"
# Get all the users who have proxyAddresses under the margiestravel.com domain
foreach ($user in (Get-ADUser -SearchBase $SearchBase -LdapFilter '(proxyAddresses=*)')) {
# Grab the primary SMTP address
$address = Get-ADUser $user -Properties proxyAddresses | Select -Expand proxyAddresses | Where {$_ -clike "SMTP:*"}
# Remove the protocol specification from the start of the address
$newUPN = $address.SubString(5)
# Update the user with their new UPN
Set-ADUser $user -UserPrincipalName $newUPN
@chrisbrownie
chrisbrownie / Monitor-Website.ps1
Created December 11, 2015 00:47
Monitors a website's status
# Site to check
$site = "https://www.github.com"
# Seconds between checks
$interval = 2
while ($true) {
$result = try { Invoke-WebRequest $site -ErrorAction silentlycontinue } catch { $null }
if ($result.statuscode -eq 200) {
Write-Host "$site is up" -BackgroundColor green -ForegroundColor white
} else {
@chrisbrownie
chrisbrownie / FixOffice365Users.ps1
Created January 18, 2016 05:25
Sets ImmutableIDs for all Office 365 users based on AD...without needing to touch anything.
function Get-ImmutableId ($a) {
[System.Convert]::ToBase64String(([guid](Get-ADUser $a -Properties ObjectGuid).ObjectGuid).ToByteArray())
}
##
## WARNING: This script does not health check anything at all.
## If you run it without knowing what it does, you
## will probably break the internet, and not in the good way.
##
@chrisbrownie
chrisbrownie / RemoveEmptyLines.ps1
Created February 19, 2016 02:04
Removes empty lines from a file
$logFile = "$pwd\dns.log"
$newLogFile = "$pwd\dns_cleaned.log"
$sr = New-Object System.IO.StreamReader($logFile)
$sw = New-Object System.IO.StreamWriter($newLogFile)
$line = $sr.ReadLine()
while ($line -ne $null) {
if ($line.trim() -ne "") {
@chrisbrownie
chrisbrownie / ParseDnsLog.ps1
Created February 19, 2016 02:26
Basics of parsing a Windows DNS Log file. Not good, but should be enough to jog the ol' memory.
$logFile = "dns2_cleaned.log"
$sr = New-Object System.IO.StreamReader($logFile)
$line = $sr.ReadLine()
$packets = @()
while ($line -ne $null) {
@chrisbrownie
chrisbrownie / Grant-SharedMailboxPermissions.ps1
Created February 24, 2016 22:09
Grants Full Access and Send On Behalf permissions to shared mailbox for a user or distribution group members (Exchange Online)
function Grant-SharedMailboxPermissions ($mailbox,$principles) {
Get-Mailbox $mailbox | Set-mailbox -GrantSendOnBehalfTo $principles
foreach ($principle in $principles) {
switch ((Get-Recipient $principle).RecipientType.ToString()) {
"UserMailbox" {
Add-MailboxPermission -Identity $mailbox -User $principle -AccessRights fullaccess -InheritanceType All
}
"MailUniversalDistributionGroup" {