Skip to content

Instantly share code, notes, and snippets.

View MauricioZa's full-sized avatar

Mauricio Zaragoza MauricioZa

View GitHub Profile
@MauricioZa
MauricioZa / CPUmonitor.ps1
Last active September 24, 2020 17:05
Monitors CPU usage. If it is above the configured percentage, a file is renamed.
<#
.SYNOPSIS
Monitors CPU usage. If it is above the configured percentage, a file is renamed
.DESCRIPTION
Monitors CPU usage. If it is above the configured percentage, a file is renamed
.PARAMETERS
All parameters are requested interactively
.EXAMPLE
./CPUmonitor.ps1.
.OUTPUTS
@MauricioZa
MauricioZa / AddTaskSchedulerTask.ps1
Last active September 24, 2020 17:38
PowerShell script to add a task to be executed in Task Scheduler
<#
.SYNOPSIS
Add a task to be executed in Task Scheduler
.DESCRIPTION
Add a task to be executed in Task Scheduler. In the example the CPUmonitor.ps1 is configured to run when the computer starts
.PARAMETERS
All parameters are requested interactively
.EXAMPLE
./AddTaskSchedulerTask.ps1.ps1
.OUTPUTS
@MauricioZa
MauricioZa / gist:278fc6d36e6da78d29fe6bb5c905073a
Created October 8, 2020 20:59
Get job status - Powershell
# Insert here the code that enables monitoring on SQL. Run the commands -asjob
# This will show you the jobs progress
do {
$report = Get-Job
$CompletedJobs = $report | Where-Object { $_.State -in 'Completed', 'Failed' }
$RunningJobs = $report | Where-Object { $_.State -contains 'Running' }
Write-Progress -Activity 'Analyzing Jobs' -Status "Completed $($CompletedJobs.count) of $($report.count)" -PercentComplete (($CompletedJobs.count / $report.count) * 100)
}
until (!$RunningJobs)
@MauricioZa
MauricioZa / TestMySQLReplica.ps1
Last active October 23, 2020 15:56
MySQL Replica testing Script
# Optional: Connect to Azure
# Connect-AzAccount
# Optional: Install MySQL module
# Install-Module -Name Az.MySql -AllowPrerelease
Clear-Host
#Variables
$PrimaryServerName = "primaryserverMAU015"
@MauricioZa
MauricioZa / SQLandOMS.ps1
Created October 13, 2020 19:34
SQL + Log Analytics
#--------------------------------------------------------------------------------------
# Login to Azure
#--------------------------------------------------------------------------------------
#region login
#Connect-AzAccount
#endregion login
#--------------------------------------------------------------------------------------
@MauricioZa
MauricioZa / newdockervm.ps1
Last active October 19, 2020 23:16
Creates VM for Docker workshop
# Credential
$VMLocalAdminUser = "dockeradmin"
$VMLocalAdminSecurePassword = ConvertTo-SecureString "@DockerWorkshop2020!!" -AsPlainText -Force
# VM name and location
$LocationName = "east us 2"
$ResourceGroupName = "rg-DockerLab-$(Get-Random)"
$ComputerName = "vm-docker"
$VMName = "vm-docker"
$VMSize = "Standard_D8s_v3"
@MauricioZa
MauricioZa / managettovhd.ps1
Created January 12, 2021 00:18
Convert Azure managed disk to VHD
# Transform managed disk to VHD to mount it in a non-managed VM
# In order to mount a managed disk to a VM with unmanaged disks you need to convert the managed disk to a VHD
# Then you will mount the resultant VHD to your unmanaged VM.
# Follow the procedure below.
# ------------------------------------------
# Variables
# ------------------------------------------
# Name of the storage account where the resultant VHD disk will be stored
# Variables
$storageAccountName = "linux78"
$storageAccountResourceGroup = "rg-Joseph"
$vmName = "linux-7-8-04"
$VMresourceGroup = "rg-Joseph"
$publicSettingsFilePath = "Z:\Mauricio\E\Trabajo\Microsoft\CSA\PwC C-AMS\C-AMS monitoring\publicSettings.json"
$protectedSettingsFilePath = "Z:\Mauricio\E\Trabajo\Microsoft\CSA\PwC C-AMS\C-AMS monitoring\protectedSettings.json"
# Connect
{
"storageAccountName" : "__DIAGNOSTIC_STORAGE_ACCOUNT__",
"storageAccountSasToken": "__SAS_TOKEN__",
"sinksConfig": {
"sink": [
]
}
}
{
"StorageAccount": "__DIAGNOSTIC_STORAGE_ACCOUNT__",
"ladCfg": {
"diagnosticMonitorConfiguration": {
"eventVolume": "Medium",
"metrics": {
"metricAggregation": [
{
"scheduledTransferPeriod": "PT1M"
},