Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
mattmcnabb / 2015AugSG.ps1
Last active August 29, 2015 14:26
2015-August Scripting Games Puzzle
# A one-liner to return the desired output
Invoke-RestMethod -Uri 'telize.com/geoip' | Select-Object longitude, latitude, continent_code, timezone
# Wrapped with a function - simple but works
Function Get-GeoInformation
{
[CmdletBinding()]
Param
(
[System.Net.IPAddress]
@mattmcnabb
mattmcnabb / Get-IPAddress.ps1
Created August 18, 2015 15:26
Get IP Addresses for Remote Computers
function Get-IPAddress
{
[CmdletBinding()]
param
(
[ValidateSet('IPv4','IPv6','All')]
[string]
$AddressType = 'All',
[Parameter(ValueFromPipelineByPropertyName,ValueFromPipeline)]
@mattmcnabb
mattmcnabb / Get-SvcHost.ps1
Last active September 15, 2015 17:30
Find Services Running in Service Host Processes
function Get-SvcHost
{
<#
.SYNOPSIS
Returns information about the processes running under each instance of the service host process.
.DESCRIPTION
Returns information about the processes running under each instance of the service host process of local or remote computers.
Uses WMI as the source of this information.
.PARAMETER ComputerName
Specifies a remote computer to gather information about. Can be a fully-qualified domain name, NetBIOS name, or and IP address.
@mattmcnabb
mattmcnabb / ShortCircuit.tests.ps1
Last active November 12, 2015 01:32
Short-Circuit Evaluation in Pester It Blocks
Describe "Example" {
It "Performs short-circuit evaluation" {
Test-Path c:\NoDirHere | Should be $true
Get-ChildItem c:\NoDirHere -File | Should Not Be $null
}
}
@mattmcnabb
mattmcnabb / 2015DecSG.ps1
Last active December 10, 2015 21:05
Scripting Games December 2015
$list = @"
1 Partridge in a pear tree
2 Turtle Doves
3 French Hens
4 Calling Birds
5 Golden Rings
6 Geese a laying
7 Swans a swimming
8 Maids a milking
9 Ladies dancing
@mattmcnabb
mattmcnabb / Test-EventLogExists.Tests.ps1
Last active April 7, 2016 18:00 — forked from gerane/Test-EventLogExists.Tests.ps1
Learning Pester and better comment based Help. Please leave feedback if you have any suggestions!
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace('.Tests.', '.')
. "$here\$sut"
Remove-EventLog -LogName Pester -ErrorAction SilentlyContinue
Describe 'Test-EventLogExists' {
Set-StrictMode -Version latest
@mattmcnabb
mattmcnabb / New-CustomObject.ps1
Created May 27, 2016 12:48
A PowerShell Custom Object Factory
function New-CustomObject
{
param
(
[Parameter(ValueFromPipeline)]
[Object]
$InputObject,
[Parameter()]
[hashtable]
function Get-O365UserLicenseReport
{
<#
.SYNOPSIS
Generates a report of Office 365 license assignments
.DESCRIPTION
Generates a report of Office 365 license assignments by license sku, including individual service plan assignments.
This command requires that you have a global administrator account for an Office 365 tenant and can connect to Office 365 using
Windows PowerShell. Instructions for this can be found at http://powershell.office.com/.
$ModulePath = Split-Path -Parent $MyInvocation.MyCommand.Path
$ModuleName = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -Replace ".Tests.ps1"
$ManifestPath = "$ModulePath\$ModuleName.psd1"
# test the module manifest - exports the right functions, processes the right formats, and is generally correct
Describe "Manifest" {
$Manifest = $null
It "has a valid manifest" {
{
@mattmcnabb
mattmcnabb / 1.ps1
Created August 21, 2016 14:47
Blog_Powershell-5-PSCredential
function Test-PSCredential
{
param
(
[PSCredential]
$Credential
)
$Credential
}