Skip to content

Instantly share code, notes, and snippets.

$vm = Get-AzVM -Status | % { Add-Member -InputObject $_ -Name "NICObj" -MemberType NoteProperty -Value (Get-AzNetworkInterface -ResourceId $_.NetworkProfile.NetworkInterfaces[0].id) -Force -PassThru } |
% { Add-Member -InputObject $_ -Name "PrivateIP" -MemberType NoteProperty -Value ($_.NICObj.IpConfigurations[0].PrivateIpAddress) -Force -PassThru} |
% { if ($_.NICObj.IpConfigurations[0].PublicIpAddress.count -gt 0) {
$rIdparsed = $_.NICObj.IpConfigurations[0].PublicIpAddress[0].Id -split "/";
Add-Member -InputObject $_ -Name "PublicIP" -MemberType NoteProperty -Value ((Get-AzPublicIpAddress -Name $rIdparsed[-1] -ResourceGroupName $rIdparsed[4]).IpAddress) -Force -PassThru
}
else {
$_
}
} |
@eosfor
eosfor / findAlertRules.ps1
Created February 1, 2022 08:55
pill alert rules and their action groups from azure where action groups have a webhook attached
$q = "resources
| where type == `"microsoft.insights/metricalerts`"
| extend prop = parse_json(properties)
| extend agId = tolower(tostring(prop.actions[0].actionGroupId))
| project metricsid = ['id'], mname = name, mresourceGroup = resourceGroup, agId
| join kind = inner ( resources
| where type == `"microsoft.insights/actiongroups`"
| extend prop = parse_json(properties)
| project actiongroupid = tolower(id), aname = name, aresourcegroup = resourceGroup, whURL = tostring(prop.webhookReceivers[0].serviceUri)
| where whURL != `"`")
@eosfor
eosfor / kube-minizinc.mzn
Last active September 17, 2021 05:59
Quick and dirty minizinc model to estimate cluster costs
include "all_equal.mzn";
% config section
int: maxClusterSize = 6;
float: minNodeRAMConsumption = 0.5;
float: maxNodeRAMConsumption = 0.8;
float: minNodeCPUConsumption = 0.1;
float: maxNodeCPUConsumption = 0.8;
% end config
@eosfor
eosfor / graphSysmonNetworkEvents.ps1
Last active October 4, 2018 16:47
graph network events from sysmon
$ids = Get-WinEvent -LogName Microsoft-Windows-Sysmon/Operational | ? {$_.id -eq 3}
$commObjects = $ids | % {
New-Object psobject -Property @{
RuleName = $_.Properties[0].value
UtcTime = $_.Properties[1].value
ProcessGuid = $_.Properties[2].value
ProcessId = $_.Properties[3].value
Image = $_.Properties[4].value
User = $_.Properties[5].value
Protocol = $_.Properties[6].value
@eosfor
eosfor / getPodStatus.ps1
Last active September 3, 2018 15:43
Get status of a pod
function Get-PodStatus {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$ContextName,
[Parameter(Mandatory = $false)]
[switch]$All
)
end {
@eosfor
eosfor / restorePasswordsOfSP.ps1
Last active August 9, 2018 11:49
When you accidentally deleted password of a security principal
$passwords = "<pwd1>",
"<pwd2>",
"<pwd3>"
$keys = $passwords | % {
$sDate = Get-Date
$eDate = $sDate.AddYears(10)
$kID = (New-Guid).Guid
$value = $_
$keydata = [Microsoft.Azure.Graph.RBAC.Version1_6.Models.PasswordCredential]::new($sDate, $eDate, $kID, $value)
@eosfor
eosfor / acsEngineSampleTemplate.json
Created August 7, 2018 11:50
acs-engine example template
{
"apiVersion": "vlabs",
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes",
"kubernetesConfig": {
"privateCluster": {
"enabled": true
},
"kubeletConfig": {
@eosfor
eosfor / aksDeploymentSample.json
Created August 7, 2018 11:48
AKS deployment sample
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterName": {
"type": "string"
},
"kubernetesVersion": {
"type": "string",
"defaultValue": "1.10.6",
@eosfor
eosfor / joinVMNicIPConfigInfo.ps1
Created July 23, 2018 09:03
Join Vm info, NIC info and Public IP info
$rgName = "kubetest"
$vms = Get-AzureRmVM -ResourceGroupName $rgName
$nics = Get-AzureRmNetworkInterface -ResourceGroupName $rgName
$pubIPs = Get-AzureRmPublicIpAddress -ResourceGroupName $rgName
$vmNics = @{}
$nics | ForEach-Object {
$index = $_.id
$value = $_
$vmNics[$index] += @($value)
function Test-Password {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$true)]
[string]$Password
)
begin {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}