Skip to content

Instantly share code, notes, and snippets.

@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 / Set-O365UserLicense.ps1
Last active April 10, 2018 16:36
Set Office 365 User Licenses Via a Template
function Set-O365UserLicense
{
<#
.SYNOPSIS
Sets licenses for Office 365 users.
.PARAMETER MsolUser
Specifies an Azure Active Directory user to set license entitlements for. Should be an object of type [Microsoft.Online.Administration.User] which is returned by the Get-MsolUser cmdlet found in the Azure Active Directory (MSOnline) module.
.PARAMETER LicenseTemplate
@mattmcnabb
mattmcnabb / Add-TaskbarItem.ps1
Created March 16, 2016 01:23
Pin or unpin applications to/from the taskbar
function Add-TaskbarItem
{
<#
.SYNOPSIS
Adds or removes items from a user's taskbar
.DESCRIPTION
Adds or removes items from a user's taskbar. Supports pinning of multiple items using the pipeline.
.PARAMETER Action
@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 / 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 / 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 / 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 / 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 / 2015JulySG.ps1
Last active August 29, 2015 14:24
2015-July Scripting Games
gwmi CIM_operatingsystem|Select PSC*,*j*,v*,@{n='BIOSSerial';e={$_.SerialNumber}}
@mattmcnabb
mattmcnabb / EnumBug.ps1
Last active August 29, 2015 14:22
Is this a bug? What's the deal?
# Add an enum with All constant
Add-Type -TypeDefinition @'
using System;
[Flags]
public enum O365Services
{
AzureActiveDirectory,
Exchange,
Sharepoint,