Skip to content

Instantly share code, notes, and snippets.

workflow Get-VMIdFromJobId {
param(
    [Parameter(Mandatory=$true)]
    [STRING]$VMMJobId    
    )
    #Get VMM Connection Object
    $vmmcon = Get-AutomationConnection -Name "SCVMM"
    #Construct the VMM Credential
@bentaylorwork
bentaylorwork / vmExtension.azuredeploy.json
Created July 4, 2017 16:04
Deploys the Microsoft IaaS Anti-malware VM extension to a previously deployed VM in Azure using an ARM template.
{
"$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"
}
}
@bentaylorwork
bentaylorwork / Get-MailboxFolderStatistics.ps1
Created August 18, 2017 10:21
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.
Get-MailboxFolderStatistics [email protected] | 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 / Get-EventLogLoginIp.ps1
Created September 29, 2017 14:49
Gets the IP of a user login from the event log. Filters out entries where the IP isn't recorded.
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
$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 / Test-AzureARMTemplateDeployment.ps1
Last active October 13, 2017 16:57
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.
$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
@bentaylorwork
bentaylorwork / azureAlert.azuredeploy.json
Created January 23, 2018 12:01
Adds an Azure alert to existing VMs to monitor Processor Queue Length with the threshold based on the VM core count and a multiplier.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmNames": {
"type": "array",
"defaultValue": [
"vm1",
"vm2"
],
$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" {
$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)