Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
mattmcnabb / 1.ps1
Created August 22, 2016 02:28
Blog_pester-testing-your-module-manifest
$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 22, 2016 02:23
Blog_Customize-The-ISE-With-Hotkeys
#requires -Version 3
function Test-KeyPress
{
<#
.SYNOPSIS
Checks to see if a key or keys are currently pressed.
.DESCRIPTION
Checks to see if a key or keys are currently pressed. If all specified keys are pressed then will return true, but if
any of the specified keys are not pressed, false will be returned.
@mattmcnabb
mattmcnabb / 1.ps1
Last active May 11, 2017 01:43
Blog_Office-365-Licensing_2
# save the license options in a variable
$Options = New-MsolLicenseOptions `
-AccountSkuId whitehouse:ENTERPRISEPACK `
-DisabledPlans SWAY, YAMMER_ENTERPRISE, SHAREPOINTWAC, MCOSTANDARD
# set the license using the saved options
Set-MsolUserLicense `
-UserPrincipalName Ronald.Reagan@whitehouse.gov `
-AddLicenses whitehouse:ENTERPRISEPACK `
-LicenseOptions $Options
@mattmcnabb
mattmcnabb / 1.ps1
Last active August 22, 2016 01:53
Blog_Office-365-Licensing_3
$User = Get-MsolUser -UserPrincipalName ronald.reagan@whitehouse.gov
$User.Licenses |
Select-Object -Property AccountSkuId,
@{
n='ServicePlans'
e={ ($_.ServiceStatus | Where-Object ProvisioningStatus -eq 'success').ServicePlan.ServiceName }
}
@mattmcnabb
mattmcnabb / 1.ps1
Last active May 11, 2017 01:48
Blog_Office-365-Licensing_4
$LicenseTemplate = @(
@{
AccountSkuId = 'whitehouse:ENTERPRISEPACK'
EnabledPlans = 'EXCHANGE_S_STANDARD','SHAREPOINTENTERPRISE','SHAREPOINTWAC','MCOSTANDARD','YAMMER_ENTERPRISE'
},
@{
AccountSkuId = 'whitehouse:PROJECTONLINE'
EnabledPlans = 'SWAY'
}
@mattmcnabb
mattmcnabb / 1.ps1
Created August 21, 2016 18:11
Blog_Pester-For-PowerShell-Gallery
It "gallery tags don't contain spaces" {
foreach ($Tag in $ManifestHash.PrivateData.Values.tags)
{
$Tag | Should Not Match '\s'
}
}
@mattmcnabb
mattmcnabb / 1.ps1
Created August 21, 2016 14:47
Blog_Powershell-5-PSCredential
function Test-PSCredential
{
param
(
[PSCredential]
$Credential
)
$Credential
}
$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" {
{
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/.
@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]