Skip to content

Instantly share code, notes, and snippets.

Ben Taylor bentaylorwork

Block or report user

Report or block bentaylorwork

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Get-AzAccessToken.ps1
$currentContext = Get-AzContext
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$azureRmProfileClient = [Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient]::new($azureRmProfile)
$azureRmProfileClient.AcquireAccessToken($currentContext.Subscription.TenantId)
View vstsVariable.tests.ps1
$vstsTasks = @(
"##vso[task.setvariable variable=foo]bar"
"##vso[task.setvariable variable=for ]bar"
"##vso[task.setvariable variable=for] bar"
"##vso[ task.setvariable variable=for]bar"
"##vso [task.setvariable variable=for]bar"
)
Describe "VSTS" {
Context "Fake Lint" {
@bentaylorwork
bentaylorwork / azureAlert.azuredeploy.json
Created Jan 23, 2018
Adds an Azure alert to existing VMs to monitor Processor Queue Length with the threshold based on the VM core count and a multiplier.
View azureAlert.azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmNames": {
"type": "array",
"defaultValue": [
"vm1",
"vm2"
],
@bentaylorwork
bentaylorwork / Test-AzureARMTemplateDeployment.ps1
Last active Oct 13, 2017
The below code takes the idea from the Azure Quick Start GitHub repo which allows you to specify place holders for ARM template parameters. The Pester test below replaces these place holders so the template can be tested without any user input.
View Test-AzureARMTemplateDeployment.ps1
$templatesFolderPath = Get-ChildItem -Path (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace('tests\unit', 'src') | Where-Object { $_.PSIsContainer -eq $true }
Describe "Test Template Againsts Endpoint" -Tags 'unit' {
foreach($templateFolderPath in $templatesFolderPath)
{
Context "Does The Template Deploy Correctly" {
$hashReturn = @{}
$ParametersObject = Get-Content -Path (Join-Path $templateFolderPath.FullName 'azuredeploy.parameters.json') | ConvertFrom-Json
View Split-AdUsersByDepartmentIntoSeperateVariables.ps1
$adUsers = Get-AdUser -Filter * -Properties name, department
$uniqueDepartments = $adUsers | Where-Object { $_.department -ne $null } | Select-Object -ExpandProperty department -Unique
foreach ($uniqueDepartment in $uniqueDepartments) {
$variableSplat = @{
'Name' = ($uniqueDepartment -replace ' ', '')
'Value' = $adUsers | Where-Object { $_.department -eq $uniqueDepartment }
}
@bentaylorwork
bentaylorwork / Get-EventLogLoginIp.ps1
Created Sep 29, 2017
Gets the IP of a user login from the event log. Filters out entries where the IP isn't recorded.
View Get-EventLogLoginIp.ps1
Get-WinEvent -Logname Security -FilterXPath "*[System[EventID=4624]]" | Where-Object { $_.Properties[18].Value -ne '-' } | Select-Object MachineName,
@{
Name = 'UserName'
Expression = { $_.Properties[5].Value }
},
@{
Name ='IP'
Expression = { $_.Properties[18].Value }
},
TimeCreated | Sort-Object -Descending UserName
@bentaylorwork
bentaylorwork / Get-MailboxFolderStatistics.ps1
Created Aug 18, 2017
Converts the string output of Get-MailboxFolderStatistics into MB that can be sorted.Not the easiest to read but functional. Only needed when running the CmdLet remotely.
View Get-MailboxFolderStatistics.ps1
Get-MailboxFolderStatistics test@test.com | Select-Object name, @{
Name="FolderSize";
Expression={
[math]::Round(([regex]::matches($_.FolderSize,'\(([^\}]+)\)').value -replace 'bytes', '' -replace '\(', '' -replace '\)', '' -replace ',', '') / 1MB, 2)
}
} | Sort-Object FolderSize -Descending
@bentaylorwork
bentaylorwork / vmExtension.azuredeploy.json
Created Jul 4, 2017
Deploys the Microsoft IaaS Anti-malware VM extension to a previously deployed VM in Azure using an ARM template.
View vmExtension.azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"metadata": {
"description": "Name of the VM"
}
}
View Get-VMIdFromJobId.ps1
workflow Get-VMIdFromJobId {
param(
    [Parameter(Mandatory=$true)]
    [STRING]$VMMJobId    
    )
    #Get VMM Connection Object
    $vmmcon = Get-AutomationConnection -Name "SCVMM"
    #Construct the VMM Credential
You can’t perform that action at this time.