Skip to content

Instantly share code, notes, and snippets.

View chrisbrownie's full-sized avatar
🛩️
computering

Chris Brown chrisbrownie

🛩️
computering
View GitHub Profile
$AllUsers = Get-Mailbox -ResultSize unlimited
$AllUsers | % {
$_.UserPrincipalName
$PhotoData = $null
$PhotoData = Get-UserPhoto -Identity $_.UserPrincipalNAme -ErrorAction SilentlyContinue
if ($PhotoData) {
[io.file]::WriteAllBytes("$pwd\$($_.UserPrincipalName).jpg",$Photodata.PictureData)
}
}
@chrisbrownie
chrisbrownie / CopyFileIntoPowerShellSession.ps1
Created October 10, 2017 22:59
Used in blog post: Copying files to a server using PowerShell Sessions
$session = New-PSSession -ComputerName MyServer
Copy-Item -Path "C:\myfile.txt" -Target "C:\SomeServerFolder" -ToSession $session
@chrisbrownie
chrisbrownie / Install-WindowsDriversFromFolder.ps1
Created September 19, 2017 06:54
Installs Windows drivers from a folder
Get-ChildItem "C:\mydrivers\" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
Param(
[String]$Path
)
$pfShortName = ($Path -replace "^\\\\[A-Za-z0-0@\-_. ]*\\All Public Folders\\","").Replace("\","_")
$FilePath = Join-Path -Path (Get-Location) -ChildPath "$pfShortName.pst"
$outlook = New-Object -ComObject Outlook.Application
$namespace = $Outlook.GetNamespace("MAPI")
@chrisbrownie
chrisbrownie / foreachas.ps1
Created August 10, 2017 05:19
Allows the pipeline'd "foreach" to be assigned a value other than $_
function foreachas {
Param(
[char]$as,
[ScriptBlock]$sb
)
PROCESS {
Set-Variable -Name $as -Value $_
Invoke-Command -ScriptBlock $sb
@chrisbrownie
chrisbrownie / OnlyWithValues.ps1
Created August 3, 2017 05:40
Returns only properties that have values
function OnlyWithValues {
PROCESS {
$properties = $_ | Get-Member | Select -ExpandProperty Name
$output = @{}
foreach ($property in $properties) {
if (-not ([String]::IsNullOrEmpty($_.$property))) {
$output[$property] = $_.$Property
}
}
return $output
#!/bin/bash
# Number of days old an access key is allowed to be
ACCESS_KEY_MAX_AGE=90
# Get every user's username
users=`aws iam list-users | jq -r '.Users[] | .UserName'`
# Get the oldest Created Date that we can allow (now minus ACCESS_KEY_MAX_AGE days)
created_date_limit=`date -d "-$ACCESS_KEY_MAX_AGE days" +%s`
@chrisbrownie
chrisbrownie / Get-PublicS3Buckets.sh
Created July 10, 2017 01:05
Returns all publicly accessible S3 buckets to which the executor has access to view the ACL
#!/bin/bash
EMPTYGRANTS='{"Grants":[]}'
buckets=`aws s3api list-buckets --output json | jq -r '.Buckets[].Name'`
for bucket in $buckets; do
acl=`aws s3api get-bucket-acl --bucket $bucket --output json | jq -c 'del(.Owner) | .Grants |= map( select(.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers") )'`
<#
.SYNOPSIS
Copies Word Custom Document Properties from one document to another
.DESCRIPTION
Given two word documents (a source and a target), this script will copy all
custom document properties from the source document to the target document.
Document properties that already exist in the target document will remain
untouched.
@chrisbrownie
chrisbrownie / vscode-settings.json
Last active July 13, 2017 03:04
My VS Code settings
// Place your settings in this file to overwrite the default settings
{
"window.zoomLevel": 1,
"editor.fontSize": 12,
"editor.formatOnType": true,
"editor.formatOnSave": true,
"editor.cursorStyle": "line",
"editor.cursorBlinking": "phase",
"editor.renderLineHighlight": "all",
"editor.renderIndentGuides": true,