Skip to content

Instantly share code, notes, and snippets.

View absolutejam's full-sized avatar

James Booth absolutejam

View GitHub Profile
@absolutejam
absolutejam / Discovery.ps1
Last active March 2, 2016 10:38
DCM - Keep file up to date
$FileToCopyPath = '\\MyFileSrv01\MyShare\MyFile.doc'
$FileToCheckPath = 'C:\Program Files\My Program\MyFile.doc'
If (!(Test-Path $FileToCheckPath)) {
Return 'False'
Break
} else {
$FileToCopyMD5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$FileToCopyHash = [System.BitConverter]::ToString($FileToCopyMD5.ComputeHash([System.IO.File]::ReadAllBytes($FileToCopyPath)))
@absolutejam
absolutejam / Snippets.ps1
Created March 3, 2016 13:24
ISE Snippets
New-ISESnippet -Title 'Match array values against string' `
-Description 'Check to see if any value of an array is in a string.' `
-Text 'if ($Array | ? { $StringToLookIn -match $_ }) {'
@absolutejam
absolutejam / VM-ClusterStatus.ps1
Last active April 5, 2016 21:38
Now FUNCTIONing (get it?!)
$ClusteredVMs = Get-ClusterResource | ? ResourceType -eq 'Virtual Machine' | Select Name
$VMs = Get-VM -ComputerName node01,node02 | Select Name
Compare-Object $VMs $ClusteredVMs -IncludeEqual
@absolutejam
absolutejam / SpeedTestRoberts.ps1
Last active April 20, 2018 12:17
Quick and dirty speed test
Function Start-SpeedTest {
param(
# How long (in minutes) to run the speedtest for
[Parameter(
Mandatory = $False
)]
[int]$Duration = 30,
# The interval (in minutes) to run the test
@absolutejam
absolutejam / FixProxyAddresses.ps1
Created May 17, 2016 14:14
Quick and dirty fix for AD/0365 users who are sending from their onmicrosoft account
Get-ADUser -Filter * `
-SearchBase (Get-ADOrganizationalUnit -Filter 'Name -like "*MY OU*"') `
-Properties ProxyAddresses,Mail |
ForEach-Object {
if (!($_.Mail)) {
Write-Host ($_.SamAccountName + ' - No mail attribute defined') -ForegroundColor Red
} else {
$NewProxyAddress = ('SMTP:' + $_.Mail)
@absolutejam
absolutejam / Remove-LongFolderPath.ps1
Created September 1, 2017 10:51
Remove-LongFolderPath
Function Remove-LongFolderPath {
[CmdletBinding()]
Param(
[Parameter(
Mandatory = $True
)]
[string]$Path,
[switch]$Force
)
@absolutejam
absolutejam / check-iscsi.ps1
Created November 2, 2017 22:40
Sensu check to ensure iSCSI connections are present & connected
#
# check-iscsi.ps1
#
# DESCRIPTION:
# This plugin checks that each ISCSI IQN passed to it is currently connected.
#
# OUTPUT:
# plain text
#
# PLATFORMS:
@absolutejam
absolutejam / file.managed
Last active November 15, 2017 21:42
Dict to list
# file.managed and cmd.run echo output
{"client": {"services": {"critical": "ReportServer$OLIVER,MSSQL$OLIVER,SoftlinkOliver"}}}
@absolutejam
absolutejam / frankenjinja.j2
Last active December 6, 2017 10:29
Convert a list to a comma separated string, within a dict
{%- macro recurse_dict(data) -%}
{%- set topdict = {} -%}
{%- for k,v in data.iteritems() %}
{%- if v is mapping -%}
{%- do topdict.update({ k: recurse_dict(v) }) -%}
{%- elif v is iterable and v is not string -%}
{%- set list_as_str = v | join(',') -%}
{%- do topdict.update({ k: list_as_str }) -%}
{%- else -%}
{%- do topdict.update({ k: v }) -%}
@absolutejam
absolutejam / check-windows-port-listening.rb
Created December 14, 2017 19:08
check-windows-port-listening.rb
#! /usr/bin/env ruby
#
# check-windows-port-listening.rb
#
# DESCRIPTION:
# Check to see which ports are listening, using netstat.
# First draft.
#
# OUTPUT:
# plain text