Skip to content

Instantly share code, notes, and snippets.

View adamdriscoll's full-sized avatar
:bowtie:

Adam Driscoll adamdriscoll

:bowtie:
View GitHub Profile
@adamdriscoll
adamdriscoll / Dictionary.ps1
Created April 1, 2015 19:02
Hashtable to Dictionary
function Dictionary
{
param([Type[]]$Type, [Hashtable]$Hashtable)
$KeyType = $Type[0]
$ValueType = $Type[1]
$Dictionary = New-Object -TypeName "System.Collections.Generic.Dictionary[$KeyType,$ValueType]"
$Hashtable.GetEnumerator() | % {
@adamdriscoll
adamdriscoll / gist:249dbe4523af19757f3c
Created September 28, 2015 22:16
Programmatically Determine EF6 Schema Validation Errors
// Programmically get a list of the changes preventing model validation.
// You'll likely see this error:
//Unable to update database to match the current model because there are pending changes and automatic migration is disabled.
//Either write the pending model changes to a code-based migration or enable automatic migration.
//Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
//This is how you can programmatically find out exactly what is preventing the validation
var migrator = new DbMigrator(new vWorkspaceMigrationConfig { TargetDatabase = new DbConnectionInfo("connectionString", "System.Data.SqlClient") });
try
{
@adamdriscoll
adamdriscoll / wsdl.ps1
Created December 8, 2015 20:07
Autogen WSDL Type Names
$Proxy = New-WebServiceProxy -Uri "https://dev.service-now.com/change_task.do?WSDL" -Credential $Credential
#
# Is there a better way to determine the auto-gen'd WSDL argument type names?
#
$ClassName = $Proxy.getRecords.OverloadDefinitions[0].Split('(')[1].Split(' ')[0]
$queryParams = new-object $ClassName
$queryParams.__encoded_query = $query
$Proxy.getRecords($queryParams)
@adamdriscoll
adamdriscoll / New-ConfigManagerDrive.ps1
Created January 4, 2016 20:51
New ConfigMgr Drive
New-PSDrive -Name "SiteName" -Root "SiteServerName" -PSProvider CMSite
@adamdriscoll
adamdriscoll / SunriseSunset.ps1
Created January 24, 2016 22:18
Scheduled job the turns on lights at sunset. OpenHAB + Wunderground
Unregister-ScheduledJob "Check Sunrise and Sunset" -Force
$MidnightTrigger = New-JobTrigger -Daily -At ([DateTime]::Today)
Register-ScheduledJob -ScriptBlock {
$astronomy = Invoke-RestMethod "http://api.wunderground.com/api/$key/astronomy/q/WI/Madison.json"
$sunRiseHour = $astronomy.sun_phase.sunrise.hour
$sunRiseMinute = $astronomy.sun_phase.sunrise.minute
$sunriseTrigger = New-JobTrigger -Once -At ([DateTime]::Today).AddHours($sunRiseHour).AddMinutes($sunRiseMinute)
@adamdriscoll
adamdriscoll / AzureAutomationError.cs
Created February 5, 2016 16:13
Azure Automation Exception
public void Authenticate()
{
SubscriptionCloudCredentials cred;
var cert = new X509Certificate2(Convert.FromBase64String(AzureSettings.ManagementCertificate));
cred = new CertificateCloudCredentials(AzureSettings.Id, cert);
var automationManagementClient = new AutomationManagementClient(cred);
var content = automationManagementClient.Runbooks.Content("<resource group>", "<automation account>", "<runbook>");
}
/* Returns the following exception
@adamdriscoll
adamdriscoll / BPTest.ps1
Created February 23, 2016 20:18
VS Code BP Foreach Variable Test
function Add-RandomScsmBulkData {
[CmdletBinding()]
param(
[String[]]$Classes,
[String[]]$Relationships,
[int]$DataSetSize = 200)
$itemCount = 0
$totalItems = ($classes.Length * $DataSetSize) + ($Relationships.Length * $DataSetSize)
@adamdriscoll
adamdriscoll / BPTestCaller.ps1
Created February 23, 2016 20:27
BPTestCaller
$Global:SMDefaultComputer = "ADSCSM3"
Import-Module "C:\Users\adriscoll\repos\ITSM%20and%20Automation%20Modules\ScsmBulkOperations\ScsmBulkOperations.psm1" -Force
Import-Module 'C:\Program Files\Common Files\SMLets\Smlets.psd1' -Force
Add-RandomScsmBulkData -Classes "CITAM.Lun$" -DataSetSize 1
@adamdriscoll
adamdriscoll / MockPester.ps1
Last active February 24, 2016 17:12
Mocking with Pester
Remove-Module 'Smlets'
Import-Module 'C:\Program Files\Common Files\SMLets\SMLets.psd1' -Force
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module (Join-Path $here "ScsmBulkOperations.psd1") -Force
Describe "Move-ScsmObject" {
$Session = New-ScsmMigrationSession -SourceComputerName 'SourceComp' -TargetComputerName 'TargetComp'
Context "When classes differ between source and target SCSM (number of properties) and strict specified" {
@adamdriscoll
adamdriscoll / workbench.main.css
Created March 7, 2016 23:16
Shows code folding indicators all the time.
/*!--------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/.hidden{display:none!important;visibility:hidden!important}.builder-visible{display:inherit;visibility:visible}.monaco-action-bar{text-align:center;overflow:hidden;white-space:nowrap}.monaco-action-bar .actions-container{display:inline-block;margin:0 auto;padding:0;width:100%}.monaco-action-bar .action-item{cursor:pointer;display:inline-block;-webkit-transition:-webkit-transform .1s ease;transition:transform .1s ease;position:relative}.monaco-action-bar .action-item.disabled{cursor:default}.monaco-action-bar .action-item.active{-webkit-transform:translateY(-3px);transform:translateY(-3px)}.monaco-action-bar .action-item .icon{display:inline-block}.monaco-action-bar .action-label{font-size:12px;margin-right:.3em}.monaco-action-bar .action-item.disabled .action-label,.monaco-action-bar .action-item.disabled .action-label:hover{opacit